// Status variabelen
int statusS1 = 30; // 30=Rd, 31=Gn
int statusS2 = 32; // 32=Rd, 33=Gn
int statusW3 = 34; // 34=Recht, 35=Afbuigend
int statusW1 = 36; // 36=Recht, 37=Afbuigend
void setup() {
for(int i = 22; i <= 29; i++) pinMode(i, INPUT_PULLUP);
for(int i = 30; i <= 37; i++) pinMode(i, OUTPUT);
updateLeds();
}
void loop() {
// Sein 1: Groen mag alleen als S2 rood is
if (digitalRead(22) == LOW) { statusS1 = 30; updateLeds(); } // S1 naar Rood
if (digitalRead(23) == LOW) {
if (statusS2 == 32) {
statusS1 = 31;
statusW3 = 35; // W3 naar Afbuigend
statusW1 = 37; // W1 naar Afbuigend
updateLeds();
}
}
// Sein 2: Groen mag alleen als S1 rood is
if (digitalRead(24) == LOW) { statusS2 = 32; updateLeds(); } // S2 naar Rood
if (digitalRead(25) == LOW) {
if (statusS1 == 30) {
statusS2 = 33;
statusW3 = 34; // W3 naar Recht
statusW1 = 36; // W1 naar Recht
updateLeds();
}
}
// Handmatige wisselbediening blijft mogelijk
if (digitalRead(26) == LOW) { statusW3 = 34; updateLeds(); }
if (digitalRead(27) == LOW) { statusW3 = 35; updateLeds(); }
if (digitalRead(28) == LOW) { statusW1 = 36; updateLeds(); }
if (digitalRead(29) == LOW) { statusW1 = 37; updateLeds(); }
delay(100);
}
void updateLeds() {
for(int i = 30; i <= 37; i++) digitalWrite(i, LOW);
digitalWrite(statusS1, HIGH);
digitalWrite(statusS2, HIGH);
digitalWrite(statusW3, HIGH);
digitalWrite(statusW1, HIGH);
}