Project Description for Function Control of (Model Railway) Points ie Servos
//Function_Control_Points//Input from DCC_Loco_fn selects Point/Servo to control in Servo_for_Points//Standard C code - but uses libraries previously generated.#include <DCC_Loco_Fn.h>#include <Servo_for_Points.h>#define LOCO 3DCC_Loco_Fn Fn;Servo_for_Points servo1(0,200,375);Servo_for_Points servo2(1,375,125); Servo_for_Points servo3(2,350,125); Servo_for_Points servo4(3,370,270); Servo_for_Points servo5(4,350,240);Servo_for_Points servo6(5,225,450);Servo_for_Points servo7(6,350,240);Servo_for_Points servo8(7,335,275); void setup() { Serial.begin(112500); Fn.begin( ); servo1.begin( ); servo2.begin( ); servo3.begin( ); servo4.begin( ); servo5.begin( ); servo6.begin( ); servo7.begin( ); servo8.begin( );}void loop() { static byte saveActive; int active = Fn.Fn_State(LOCO); if (active < 256) { //valid reading if (active ^ saveActive) { //new reading Serial.println (active, HEX); saveActive = active; servo1.do_servo(active&0x01); servo2.do_servo((active&0x01)); servo3.do_servo((active&0x04)>>2); servo4.do_servo((active&0x08)>>3); servo5.do_servo((active&0x10)>>4); servo6.do_servo((active&0x20)>>5); servo7.do_servo((active&0x40)>>6); servo8.do_servo((active&0x80)>>7); } //new reading } // valid reading}