Abstract/Summary: The HTML page/project will use an array of the LDR_Signals3_Class to operate/flash signals as the train passes.
Possible Audience: Railway enthusiasts who wish to control several signals. Cpp programmers interested in using arrays of objects.
Keywords: Object array, Cpp Class/Library, Cpp inheritance
Components: Any microcontroller with 12 output and 4 input pins. (Tested with Arduino NANO). 4 off LED,Red,Amber and Green LEDs 4 off 1k and 4.7k resistors
Required Software Libraries: LDE_Signals3_Class. This library inherits LDR_Sensor_Class and Signals3_Class.
A previous project LDR_Signals3_Class developed a class that monitored a single sensor and when a train was detected the signals went through a RED-AMBER-GREEN sequence. This project will use multiple instances of the LDR_Signals3_Class to go through the RED-AMBER-GREEN sequence as the trains pass. The test layout is shown below with 4 sensors and 4 sets of lights. (The direction of train travel is not important for this project.)
The test circuit is shown across. However any number of instances of LDR_Signals3_Class may be used depending upon the number of pins on the chosen micro-controller.
The test circuit uses positive logic signals. That is the LEDs are turned on by pulling the inputs high. With negative logic the signals are pulled low. (LEDs will be reversed and the 1K resistor will go to the 3.3 volt supply).
The LDR_Signals3_Class will handle both positive and negative signals.
The test circuit for bench testing is shown below. (The LDRs were too close to the GREEN Leds so the LDRs were permanently ON - to reduce the light the 1k resistors were replaced with 10K.
The program was developed using the Arduino IDE. Since the project uses the LDR_Sensors3_Class it will be necessary to:
1. (If not available) obtain a copy of the LDR_Sensors3_Class library plus any inherited libraries and place these in the libraries folder. Wile messy one solution is to perform the 3 projects LDR_Sensor_Class, Signals3_Class and LDR_Sensors3_Class and create a *.zip file of each *.cpp and *.h files . In the Arduino IDE select sketch-->include library --> add .zip library and select each library.
2. Create a new program. I have given the example the name LDR_Sensors3_Array.
3.In the Arduino IDE select sketch-->include library --> add .zip library and add LDR_Sensors3_Class from the list of contributed libraries.
The Arduino compiler will now look for LDR_Signals3_Class.h in the libraries folder.
The program LDR_Signals3_Array is shown below. The header file was loaded using the sequence sketch-->include library --> add .zip library and add LDR_Sensors3_Class from the list of contributed libraries as noted in the previous section.
In the example an array of 4 instances or objects of the class LDR_Signals3_Class is created. The first instance is attached to the Arduino NANO pins A0, 2, 3 and 4. etc
To initialise the system the begin( ) method is called for all elements of the array. As illustrated below the begin( ) will call the LDR_Sensor_Class:: begin( ) and Signals3_Class::begin(polarity ). The Signals3_Class::begin(polarity) expects as its argument the polarity of the signals. The setup( ) method defines POLARITY as "1" for positive signals.
As shown the LDR_Sensor_Class has the method train_over_sensor( ) that returns the state of the sensor while Signals3_Class has a method control_signals(int) where the argument of 1 will set the signal to RED. When the input is removed the signals go through a RED-AMBER-GREEN sequence.
This project illustrated how quickly it is to implement a project using existing libraries.
As given the libraries had the following timings:
The LDR_Sensor_Class had a 1 second filter. This implies the ouput never returned to the "no_train" condition until one second after the train actually passed.
The RED-AMBER-GREEN sequence had delays both set to 5 seconds in the Signals3_Class.
As given, after a train passed the sensor RED was active for 6 seconds (1+5), then AMBER for 5 seconds. If necessary by digging deep into these two classes those times could be altered.
A future project will implement a design where the signals are set RED when a train arrives, AMBER when it reaches the next sensor and GREEN the following.