This program enhances the project Function_Control_Points to include operating Railway Signals and an LCD display to give the status of the points.
Link for this project XFunction_Control_Points.
//Function_Control_Points -extended//Program Function_Control_Points is extended to include a LCD diplay.//Input from DCC_Loco_fn selects Point/Servo to control in Servo_for_Points Class//Standard C code - but uses libraries previously generated.#include <LCD_1602.h>LCD_1602 LCD;#include <Wire.h>#include <Adafruit_PWMServoDriver.h>Adafruit_PWMServoDriver signals(0x40);#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 Dsp_setting(int sig){ LCD.setCursor(8,1); if (sig&1) sig |= 2; else sig &= 0xFD; for (int pt = 0; pt<8; pt++){ if (sig & 1) LCD.message("N"); else LCD.message("T"); sig /=2; }}void Dsp_signals ( int sig){ if (sig&1) sig |= 2; else sig &= 0xFD; for (int ch = 8; ch <16; ch++) { if (sig & 1) signals.setPWM(ch,0,4096); else signals.setPWM(ch,0,4095); //signals.setPWM(8,0,4096); delay(500); signals.setPWM(8,0,4095); delay(500); sig /= 2; }}void setup() { Serial.begin(112500); Fn.begin( ); servo1.begin( ); servo2.begin( ); servo3.begin( ); servo4.begin( ); servo5.begin( ); servo6.begin( ); servo7.begin( ); servo8.begin( ); LCD.begin( ); LCD.message(0,"Point: 12345678"); LCD.message(1,"Setting:--------"); Dsp_signals(0xff); //Initialize signals}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); Dsp_setting(active); //change signals after points changed Dsp_signals(active); } //new reading } // valid reading}