/*
Forum: https://forum.arduino.cc/t/changing-led-state-with-ir-sensors/1434325/11
Wokwi: https://wokwi.com/projects/458102389315662849
Block Class including one Signal Light, two Entry Sensors, considering that the release may be triggered several
times while the train passes the end of block
starts with green signal
press red or green button (train enters block from LEFT or RIGHT)
signal switches to red
press green or red button (train starts leaving block to the RIGHT or to the LEFT)
release green or red button for at least minReleaseTime (train hast completely left the block)
signal switches to green again
If the button that signalizes the leaving of a block is pressed again within minReleaseTime the block will
be considered to be still occupied.
2026/03/10
ec2021
*/
#include "railroadblock.h"
blockClass block1( 1, // block identifier
12, // red pin
11, // green pin
7, // sensor left side
6, // sensor right side
1000); // minimum time [ms] that the sensor has to be released to set the signal to green again
blockClass block2( 2, // block identifier
A0, // red pin
A1, // green pin
A2, // sensor left side
A3, // sensor right side
1000); // minimum time [ms] that the sensor has to be released to set the signal to green again
void setup() {
Serial.begin(115200);
Serial.println("Start");
block1.begin();
block2.begin();
}
void loop() {
block1.run();
block2.run();
}