added trainsignal sketch

This commit is contained in:
Otto Naderer 2022-02-06 17:22:06 +01:00
parent 25991ec86d
commit 35baa17bdb

View File

@ -0,0 +1,61 @@
/* sketch of a mini train signal used with wooden toy trains
* 2019 / otto@socialnerds.org
* it's based off a standard signal of the austrian railways, uses
* 1 red, 1 yellow and two green lights. it cycles though the four
* sets it can show */
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
clearLights();
setHalt();
delay(5000);
clearLights();
setDrive();
delay(5000);
clearLights();
setDrive60();
delay(5000);
clearLights();
setDrive40();
delay(5000);
}
void clearLights()
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(1000);
}
void setHalt()
{
digitalWrite(2, LOW);
}
void setDrive()
{
digitalWrite(3, LOW);
}
void setDrive60()
{
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
void setDrive40()
{
digitalWrite(3, LOW);
digitalWrite(5, LOW);
}