#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialiseer het LCD-scherm op I2C adres 0x27, 16 tekens breed, 2 regels hoog
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Timer voor het leegmaken van het LCD-scherm
unsigned long lcdWistTijd = 0;
bool lcdMoetWissen = false;
// Deze moet bovenaan staan, zodat elke functie hem kan zien
const byte cijfers[] = {
0b11000000, // 0
0b11111001, // 1
0b10100100, // 2
0b10110000, // 3
0b10011001, // 4
0b10010010, // 5
0b10000010, // 6
0b11111000, // 7
0b10000000, // 8
0b10010000 // 9
};
// ==========================================
// PIN DEFINITIES (EXACT VOLGENS JOUW PANEEL)
// ==========================================
const int DS_PIN = 53;
const int STCP_PIN = 52;
const int SHCP_PIN = 51;
// Buffer voor de twee registers
byte regData[2] = {0b11111111, 0b11111111};
// Wissels
const int PIN_W1R_BTN = 2;
const int PIN_W1A_LED = 5;
const int PIN_W2R_BTN = 6;
const int PIN_W2R_LED = 7;
const int PIN_W2A_BTN = 8;
const int PIN_W2A_LED = 9;
const int PIN_W1R_LED = 3;
const int PIN_W1A_BTN = 4;
const int PIN_W3R_BTN = 22;
const int PIN_W3R_LED = 23;
const int PIN_W3A_BTN = 24;
const int PIN_W3A_LED = 25;
const int PIN_W11R_BTN = 26;
const int PIN_W11R_LED = 27;
const int PIN_W11A_BTN = 28;
const int PIN_W11A_LED = 29;
const int PIN_W12R_BTN = 30;
const int PIN_W12R_LED = 31;
const int PIN_W12A_BTN = 32;
const int PIN_W12A_LED = 33;
// Seinen (Common Anode: LOW = AAN, HIGH = UIT)
const int PIN_S1R_BTN = 34;
const int PIN_S1R_LED = 35;
const int PIN_S1G_BTN = 36;
const int PIN_S1G_LED = 37;
const int PIN_S2R_BTN = 38;
const int PIN_S2R_LED = 39;
const int PIN_S2G_BTN = 40;
const int PIN_S2G_LED = 41;
const int PIN_S3R_BTN = 42;
const int PIN_S3R_LED = 43;
const int PIN_S3G_BTN = 44;
const int PIN_S3G_LED = 45;
const int PIN_S4R_BTN = 46;
const int PIN_S4R_LED = 47;
const int PIN_S4G_BTN = 48;
const int PIN_S4G_LED = 49;
// Bezetmelders (Zitten aan GND: HIGH = AAN, LOW = UIT)
const int PIN_BM1_LED = A0; // Gecorrigeerd naar A0
const int PIN_BM2_LED = A1; // Gecorrigeerd naar A1
const int PIN_BM3_LED = A2;
const int PIN_BM4_LED = A3;
// Lichtschakelaars & Controle-LEDs
const int PIN_SW_LG1 = A6; const int PIN_LED_LG1 = A5;
const int PIN_SW_LG2 = A8; const int PIN_LED_LG2 = A7;
const int PIN_SW_LG3 = A10; const int PIN_LED_LG3 = A9;
const int PIN_SW_LG4 = A12; const int PIN_LED_LG4 = A11;
const int PIN_SW_LG5 = A14; const int PIN_LED_LG5 = A13;
const int PIN_SW_LG6 = 50; const int PIN_LED_LG6 = A15;
// Timer Schakelaar SW1
const int PIN_SW_TIMER = A4;
// Statusvariabelen
bool vorige_staat_lg1 = HIGH;
bool vorige_staat_lg2 = HIGH;
bool vorige_staat_lg3 = HIGH;
bool vorige_staat_lg4 = HIGH;
bool vorige_staat_lg5 = HIGH;
bool vorige_staat_lg6 = HIGH;
bool vorige_staat_sw_timer = HIGH;
bool state_bm1 = false;
bool state_bm2 = false;
bool state_bm3 = false;
bool state_bm4 = false;
bool s1_is_rood = true;
bool s2_is_rood = true;
bool s3_is_rood = true;
bool s4_is_rood = true;
// Handmatige rijwegen timer (3000 ms)
unsigned long wisselActieTijd = 0;
bool wachtOpSeinGroen = false;
int actiefSeinDoel = 0;
// Automatische trein-wissel via Reedcontacten
unsigned long automatischeTimerStart = 0;
bool automatischeTimerActief = false;
int automatischeRijwegDoel = 0;
const unsigned long timerDuur = 10000;
// Functie-declaraties
void schrijfSein(int id, bool rood);
void schrijfWissel(int id, bool recht);
void leisKnoppen();
void leesSchakelaars();
void leesSerial();
void stuurVertraagdeSeinen();
void stuurAutomatischeTimer();
void toonOpLCD(String regel1, String regel2);
void updateLCDWissen();
void setup() {
Serial.begin(9600);
const byte cijfers[] = {
0b11000000, // 0
0b11111001, // 1
0b10100100, // 2
0b10110000, // 3
0b10011001, // 4
0b10010010, // 5
0b10000010, // 6
0b11111000, // 7
0b10000000, // 8
0b10010000 // 9
};
lcd.init();
lcd.backlight();
toonOpLCD("Systeem Start..", "Seinen op ROOD");
int inputPins[] = {
PIN_W1R_BTN, PIN_W1A_BTN, PIN_W2R_BTN, PIN_W2A_BTN,
PIN_W3R_BTN, PIN_W3A_BTN, PIN_W11R_BTN, PIN_W11A_BTN, PIN_W12R_BTN, PIN_W12A_BTN,
PIN_S1R_BTN, PIN_S1G_BTN, PIN_S2R_BTN, PIN_S2G_BTN,
PIN_S3R_BTN, PIN_S3G_BTN, PIN_S4R_BTN, PIN_S4G_BTN,
PIN_SW_LG1, PIN_SW_LG2, PIN_SW_LG3, PIN_SW_LG4, PIN_SW_LG5, PIN_SW_LG6,
PIN_SW_TIMER
};
for (int pin : inputPins) {
pinMode(pin, INPUT_PULLUP);
}
int leds[] = {
PIN_W1R_LED, PIN_W1A_LED, PIN_W2R_LED, PIN_W2A_LED,
PIN_W3R_LED, PIN_W3A_LED, PIN_W11R_LED, PIN_W11A_LED, PIN_W12R_LED, PIN_W12A_LED,
PIN_S1R_LED, PIN_S1G_LED, PIN_S2R_LED, PIN_S2G_LED,
PIN_S3R_LED, PIN_S3G_LED, PIN_S4R_LED, PIN_S4G_LED,
PIN_BM1_LED, PIN_BM2_LED, PIN_BM3_LED, PIN_BM4_LED,
PIN_LED_LG1, PIN_LED_LG2, PIN_LED_LG3, PIN_LED_LG4, PIN_LED_LG5, PIN_LED_LG6
};
for (int pin : leds) {
pinMode(pin, OUTPUT);
pinMode(DS_PIN, OUTPUT);
pinMode(STCP_PIN, OUTPUT);
pinMode(SHCP_PIN, OUTPUT);
updateRegisters(); // Zorg dat ze bij start op 0b11111111 (UIT) staan
}
// Seinen initialiseren op ROOD
schrijfSein(1, true);
schrijfSein(2, true);
schrijfSein(3, true);
schrijfSein(4, true);
schrijfWissel(1, true);
schrijfWissel(2, true);
schrijfWissel(3, true);
schrijfWissel(11, true);
schrijfWissel(12, true);
// Alle bezetmelders standaard UIT bij opstarten (GND polariteit, dus LOW is uit)
digitalWrite(PIN_BM1_LED, LOW);
digitalWrite(PIN_BM2_LED, LOW);
digitalWrite(PIN_BM3_LED, LOW);
digitalWrite(PIN_BM4_LED, LOW);
vorige_staat_lg1 = digitalRead(PIN_SW_LG1);
vorige_staat_lg2 = digitalRead(PIN_SW_LG2);
vorige_staat_lg3 = digitalRead(PIN_SW_LG3);
vorige_staat_lg4 = digitalRead(PIN_SW_LG4);
vorige_staat_lg5 = digitalRead(PIN_SW_LG5);
vorige_staat_lg6 = digitalRead(PIN_SW_LG6);
digitalWrite(PIN_LED_LG1, (vorige_staat_lg1 == LOW) ? HIGH : LOW);
digitalWrite(PIN_LED_LG2, (vorige_staat_lg2 == LOW) ? HIGH : LOW);
digitalWrite(PIN_LED_LG3, (vorige_staat_lg3 == LOW) ? HIGH : LOW);
digitalWrite(PIN_LED_LG4, (vorige_staat_lg4 == LOW) ? HIGH : LOW);
digitalWrite(PIN_LED_LG5, (vorige_staat_lg5 == LOW) ? HIGH : LOW);
digitalWrite(PIN_LED_LG6, (vorige_staat_lg6 == LOW) ? HIGH : LOW);
vorige_staat_sw_timer = digitalRead(PIN_SW_TIMER);
Serial.println("Systeem Gestart: Seinen op ROOD, Wissels op RECHT.");
delay(1000);
toonOpLCD("Systeem Standby", "Wachten op trein");
}
void loop() {
leisKnoppen();
leesSchakelaars();
leesSerial();
stuurVertraagdeSeinen();
stuurAutomatischeTimer();
updateLCDWissen();
}
void toonOpLCD(String regel1, String regel2) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(regel1);
lcd.setCursor(0, 1);
lcd.print(regel2);
lcdWistTijd = millis();
lcdMoetWissen = true;
}
void updateLCDWissen() {
if (lcdMoetWissen && (millis() - lcdWistTijd >= 4000)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Systeem Standby");
lcd.setCursor(0, 1);
if (digitalRead(PIN_SW_TIMER) == LOW) {
lcd.print("Auto-Timer: AAN");
} else {
lcd.print("Auto-Timer: UIT");
}
lcdMoetWissen = false;
}
}
void leesSchakelaars() {
bool huidige_staat_timer = digitalRead(PIN_SW_TIMER);
if (huidige_staat_timer != vorige_staat_sw_timer) {
if (huidige_staat_timer == LOW) {
Serial.println("Automatische timer INgeschakeld");
toonOpLCD("Auto-Timer", "INgeschakeld");
} else {
Serial.println("Automatische timer UITgeschakeld");
toonOpLCD("Auto-Timer", "UITgeschakeld");
}
vorige_staat_sw_timer = huidige_staat_timer;
delay(50);
}
if (digitalRead(PIN_SW_LG1) != vorige_staat_lg1) { delay(50); vorige_staat_lg1 = digitalRead(PIN_SW_LG1); digitalWrite(PIN_LED_LG1, (vorige_staat_lg1 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg1 == LOW ? "L1_A" : "L1_U"); }
if (digitalRead(PIN_SW_LG2) != vorige_staat_lg2) { delay(50); vorige_staat_lg2 = digitalRead(PIN_SW_LG2); digitalWrite(PIN_LED_LG2, (vorige_staat_lg2 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg2 == LOW ? "L2_A" : "L2_U"); }
if (digitalRead(PIN_SW_LG3) != vorige_staat_lg3) { delay(50); vorige_staat_lg3 = digitalRead(PIN_SW_LG3); digitalWrite(PIN_LED_LG3, (vorige_staat_lg3 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg3 == LOW ? "L3_A" : "L3_U"); }
if (digitalRead(PIN_SW_LG4) != vorige_staat_lg4) { delay(50); vorige_staat_lg4 = digitalRead(PIN_SW_LG4); digitalWrite(PIN_LED_LG4, (vorige_staat_lg4 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg4 == LOW ? "L4_A" : "L4_U"); }
if (digitalRead(PIN_SW_LG5) != vorige_staat_lg5) { delay(50); vorige_staat_lg5 = digitalRead(PIN_SW_LG5); digitalWrite(PIN_LED_LG5, (vorige_staat_lg5 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg5 == LOW ? "L5_A" : "L5_U"); }
if (digitalRead(PIN_SW_LG6) != vorige_staat_lg6) { delay(50); vorige_staat_lg6 = digitalRead(PIN_SW_LG6); digitalWrite(PIN_LED_LG6, (vorige_staat_lg6 == LOW) ? HIGH : LOW); Serial.println(vorige_staat_lg6 == LOW ? "L6_A" : "L6_U"); }
}
void leisKnoppen() {
bool systeemBezet = wachtOpSeinGroen || automatischeTimerActief;
if (digitalRead(PIN_W1R_BTN) == LOW) { schrijfWissel(1, true); toonOpLCD("Handmatig: W1", "RECHT"); delay(250); }
if (digitalRead(PIN_W1A_BTN) == LOW) { schrijfWissel(1, false); toonOpLCD("Handmatig: W1", "AFBUIGEND"); delay(250); }
if (digitalRead(PIN_W2R_BTN) == LOW) { schrijfWissel(2, true); toonOpLCD("Handmatig: W2", "RECHT"); delay(250); }
if (digitalRead(PIN_W2A_BTN) == LOW) { schrijfWissel(2, false); toonOpLCD("Handmatig: W2", "AFBUIGEND"); delay(250); }
if (digitalRead(PIN_W3R_BTN) == LOW) { schrijfWissel(3, true); toonOpLCD("Handmatig: W3", "RECHT"); delay(250); }
if (digitalRead(PIN_W3A_BTN) == LOW) { schrijfWissel(3, false); toonOpLCD("Handmatig: W3", "AFBUIGEND"); delay(250); }
if (digitalRead(PIN_W11R_BTN) == LOW) { schrijfWissel(11, true); toonOpLCD("Handmatig: W11", "RECHT"); delay(250); }
if (digitalRead(PIN_W11A_BTN) == LOW) { schrijfWissel(11, false); toonOpLCD("Handmatig: W11", "AFBUIGEND"); delay(250); }
if (digitalRead(PIN_W12R_BTN) == LOW) { schrijfWissel(12, true); toonOpLCD("Handmatig: W12", "RECHT"); delay(250); }
if (digitalRead(PIN_W12A_BTN) == LOW) { schrijfWissel(12, false); toonOpLCD("Handmatig: W12", "AFBUIGEND"); delay(250); }
if (digitalRead(PIN_S1R_BTN) == LOW) { schrijfSein(1, true); toonOpLCD("Handmatig: S1", "Naar ROOD"); delay(250); }
if (digitalRead(PIN_S2R_BTN) == LOW) { schrijfSein(2, true); toonOpLCD("Handmatig: S2", "Naar ROOD"); delay(250); }
if (digitalRead(PIN_S3R_BTN) == LOW) { schrijfSein(3, true); toonOpLCD("Handmatig: S3", "Naar ROOD"); delay(250); }
if (digitalRead(PIN_S4R_BTN) == LOW) { schrijfSein(4, true); toonOpLCD("Handmatig: S4", "Naar ROOD"); delay(250); }
if (digitalRead(PIN_S1G_BTN) == LOW && !systeemBezet) {
if (s2_is_rood) {
toonOpLCD("Rijweg Spoor 1", "Wissels omzetten");
schrijfWissel(3, true); schrijfWissel(1, true);
wisselActieTijd = millis(); wachtOpSeinGroen = true; actiefSeinDoel = 1;
} delay(250);
}
if (digitalRead(PIN_S2G_BTN) == LOW && !systeemBezet) {
if (s1_is_rood) {
toonOpLCD("Rijweg Spoor 2", "Wissels omzetten");
schrijfWissel(3, false); schrijfWissel(1, false);
wisselActieTijd = millis(); wachtOpSeinGroen = true; actiefSeinDoel = 2;
} delay(250);
}
if (digitalRead(PIN_S3G_BTN) == LOW && !systeemBezet) {
if (s4_is_rood) {
toonOpLCD("Rijweg Inrij 3", "Wissels omzetten");
schrijfWissel(12, false); schrijfWissel(11, false);
wisselActieTijd = millis(); wachtOpSeinGroen = true; actiefSeinDoel = 3;
} delay(250);
}
if (digitalRead(PIN_S4G_BTN) == LOW && !systeemBezet) {
if (s3_is_rood) {
toonOpLCD("Rijweg Inrij 4", "Wissels omzetten");
schrijfWissel(12, true); schrijfWissel(11, true);
wisselActieTijd = millis(); wachtOpSeinGroen = true; actiefSeinDoel = 4;
} delay(250);
}
}
void stuurVertraagdeSeinen() {
if (wachtOpSeinGroen && (millis() - wisselActieTijd >= 3000)) {
if (actiefSeinDoel == 1) { schrijfSein(2, true); schrijfSein(1, false); toonOpLCD("Rijweg open!", "Sein S1 -> GROEN"); }
if (actiefSeinDoel == 2) { schrijfSein(1, true); schrijfSein(2, false); toonOpLCD("Rijweg open!", "Sein S2 -> GROEN"); }
if (actiefSeinDoel == 3) { schrijfSein(4, true); schrijfSein(3, false); toonOpLCD("Rijweg open!", "Sein S3 -> GROEN"); }
if (actiefSeinDoel == 4) { schrijfSein(3, true); schrijfSein(4, false); toonOpLCD("Rijweg open!", "Sein S4 -> GROEN"); }
wachtOpSeinGroen = false; actiefSeinDoel = 0;
}
}
void stuurAutomatischeTimer() {
if (automatischeTimerActief) {
// 1. Bereken resterende tijd
unsigned long verstreken = millis() - automatischeTimerStart;
int resterend = (verstreken < timerDuur) ? (timerDuur - verstreken) / 1000 : 0;
// 2. Display update (alleen als de seconde is veranderd)
static int oudeSeconde = 99;
if (resterend != oudeSeconde) {
updateDisplay(automatischeRijwegDoel, resterend); // Stuurt naar juiste display
oudeSeconde = resterend;
}
// 3. Controleer of de timer klaar is
if (verstreken >= timerDuur) {
if (automatischeRijwegDoel == 1) {
schrijfSein(2, true);
schrijfWissel(3, true); schrijfWissel(1, true); schrijfSein(1, false);
Serial.println("-> [Timer klaar]: Spoor 1 is nu OPEN");
toonOpLCD("Auto: Spoor 1", "S1 is nu GROEN");
}
else if (automatischeRijwegDoel == 2) {
schrijfSein(1, true);
schrijfWissel(3, false); schrijfWissel(1, false); schrijfSein(2, false);
Serial.println("-> [Timer klaar]: Spoor 2 is nu OPEN");
toonOpLCD("Auto: Spoor 2", "S2 is nu GROEN");
}
// Timer stoppen en displays uit (0b11111111 is "UIT")
regData[0] = 0b11111111;
regData[1] = 0b11111111;
updateRegisters();
automatischeTimerActief = false;
automatischeRijwegDoel = 0;
oudeSeconde = 99; // Reset voor volgende keer
}
}
}
void leesSerial() {
if (Serial.available() > 0) {
String invoer = Serial.readStringUntil('\n');
invoer.trim();
// Reedcontacten (K of L)
if (invoer == "K" || invoer == "REED1") {
if (automatischeTimerActief || wachtOpSeinGroen) {
Serial.println("!! INTERLOCKING BLOKKADE: Commando K genegeerd, systeem is bezet!");
toonOpLCD("BLOKKADE (K)", "Systeem bezet!");
}
else if (digitalRead(PIN_SW_TIMER) == LOW) {
Serial.println("Reedcontact Spoor 1 geactiveerd! Overstaptijd (5 sec) gestart...");
toonOpLCD("Trein op Spoor 1", "Wacht 5 sec...");
automatischeTimerStart = millis(); automatischeTimerActief = true; automatischeRijwegDoel = 2;
} else {
Serial.println("Reedcontact Spoor 1 geactiveerd! (Timer genegeerd: SW1 staat uit)");
toonOpLCD("Reed 1 Actief", "Genegeerd (SW=UIT)");
}
}
else if (invoer == "L" || invoer == "REED2") {
if (automatischeTimerActief || wachtOpSeinGroen) {
Serial.println("!! INTERLOCKING BLOKKADE: Commando L genegeerd, systeem is bezet!");
toonOpLCD("BLOKKADE (L)", "Systeem bezet!");
}
else if (digitalRead(PIN_SW_TIMER) == LOW) {
Serial.println("Reedcontact Spoor 2 geactiveerd! Overstaptijd (5 sec) gestart...");
toonOpLCD("Trein op Spoor 2", "Wacht 5 sec...");
automatischeTimerStart = millis(); automatischeTimerActief = true; automatischeRijwegDoel = 1;
} else {
Serial.println("Reedcontact Spoor 2 geactiveerd! (Timer genegeerd: SW1 staat uit)");
toonOpLCD("Reed 2 Actief", "Genegeerd (SW=UIT)");
}
}
// Handmatige commando's A en B
else if (invoer == "A") {
if (automatischeTimerActief) {
Serial.println("!! BEVEILIGING: Commando A genegeerd! Er loopt een automatische overstaptimer.");
toonOpLCD("Geweigerd: M_A", "Timer loopt nog");
} else {
schrijfSein(1, true); schrijfSein(2, true); schrijfSein(3, false);
Serial.println("CMD_A");
Serial.println("Commando A verwerkt: Sein 1 & 2 naar ROOD, Sein 3 naar GROEN.");
toonOpLCD("Commando A", "S1+2=R, S3=GROEN");
}
}
else if (invoer == "B") {
if (automatischeTimerActief) {
Serial.println("!! BEVEILIGING: Commando B genegeerd! Er loopt een automatische overstaptimer.");
toonOpLCD("Geweigerd: M_B", "Timer loopt nog");
} else {
schrijfSein(3, true); schrijfSein(4, true);
Serial.println("CMD_B");
Serial.println("Commando B verwerkt: Sein 3 & 4 naar ROOD.");
toonOpLCD("Commando B", "Sein 3 + 4 = ROOD");
}
}
// Bezetmelders (Allemaal uniform naar GND: HIGH is AAN, LOW is UIT)
else if (invoer == "BM1") { state_bm1 = !state_bm1; digitalWrite(PIN_BM1_LED, state_bm1 ? HIGH : LOW); toonOpLCD("Bezetmelder 1", state_bm1 ? "BEZET (AAN)" : "VRIJ (UIT)"); }
else if (invoer == "BM2") { state_bm2 = !state_bm2; digitalWrite(PIN_BM2_LED, state_bm2 ? HIGH : LOW); toonOpLCD("Bezetmelder 2", state_bm2 ? "BEZET (AAN)" : "VRIJ (UIT)"); }
else if (invoer == "BM3") { state_bm3 = !state_bm3; digitalWrite(PIN_BM3_LED, state_bm3 ? HIGH : LOW); toonOpLCD("Bezetmelder 3", state_bm3 ? "BEZET (AAN)" : "VRIJ (UIT)"); }
else if (invoer == "BM4") { state_bm4 = !state_bm4; digitalWrite(PIN_BM4_LED, state_bm4 ? HIGH : LOW); toonOpLCD("Bezetmelder 4", state_bm4 ? "BEZET (AAN)" : "VRIJ (UIT)"); }
}
}
// Common Anode (gezamenlijke plus): LOW is AAN, HIGH is UIT
void schrijfSein(int id, bool rood) {
Serial.print("S");
Serial.print(id);
Serial.println(rood ? "_R" : "_G");
if (id == 1) { s1_is_rood = rood; digitalWrite(PIN_S1R_LED, rood ? LOW : HIGH); digitalWrite(PIN_S1G_LED, rood ? HIGH : LOW); }
else if (id == 2) { s2_is_rood = rood; digitalWrite(PIN_S2R_LED, rood ? LOW : HIGH); digitalWrite(PIN_S2G_LED, rood ? HIGH : LOW); }
else if (id == 3) { s3_is_rood = rood; digitalWrite(PIN_S3R_LED, rood ? LOW : HIGH); digitalWrite(PIN_S3G_LED, rood ? HIGH : LOW); }
else if (id == 4) { s4_is_rood = rood; digitalWrite(PIN_S4R_LED, rood ? LOW : HIGH); digitalWrite(PIN_S4G_LED, rood ? HIGH : LOW); }
}
void schrijfWissel(int id, bool recht) {
Serial.print("W");
Serial.print(id);
Serial.println(recht ? "_R" : "_A");
if (id == 1) { digitalWrite(PIN_W1R_LED, recht ? HIGH : LOW); digitalWrite(PIN_W1A_LED, recht ? LOW : HIGH); }
else if (id == 2) { digitalWrite(PIN_W2R_LED, recht ? HIGH : LOW); digitalWrite(PIN_W2A_LED, recht ? LOW : HIGH); }
else if (id == 3) { digitalWrite(PIN_W3R_LED, recht ? HIGH : LOW); digitalWrite(PIN_W3A_LED, recht ? LOW : HIGH); }
else if (id == 11) { digitalWrite(PIN_W11R_LED, recht ? HIGH : LOW); digitalWrite(PIN_W11A_LED, recht ? LOW : HIGH); }
else if (id == 12) { digitalWrite(PIN_W12R_LED, recht ? HIGH : LOW); digitalWrite(PIN_W12A_LED, recht ? LOW : HIGH); }
}
void updateRegisters() {
digitalWrite(STCP_PIN, LOW);
shiftOut(DS_PIN, SHCP_PIN, MSBFIRST, regData[1]); // SR2
shiftOut(DS_PIN, SHCP_PIN, MSBFIRST, regData[0]); // SR1
digitalWrite(STCP_PIN, HIGH);
}
void updateDisplay(int spoor, int waarde) {
if (waarde >= 0 && waarde <= 9) {
if (spoor == 1) regData[0] = cijfers[waarde];
else regData[1] = cijfers[waarde];
updateRegisters();
}
}w1r
w1a
w2r
w2a
w3r
w3a
w11r
w11a
w12r
w12a
s1r
s1g
s2r
s2g
s3r
s3g
s4r
s4g
bm1
bm2
bm3
bm4
timer aan/uit
spoor 1 en 2
lichtschakelaar
groep 1
lichtschakelaar
groep 2
lichtschakelaar
groep 3
lichtschakelaar
groep 4
lichtschakelaar
groep 5
lichtschakelaar
groep 6