// Signalsteuerung Hp0 / Hp1 / Hp2 / Sh1 // Automatischer Fall auf Hp0 nach 3 Runden (2 Reedkontakte, Gruppensignal) // plus 4 manuelle Taster zur Signalwahl (Hp0 manuell = normaler Haltruf) // Arduino Nano const int S1_PIN = 2; // Reedkontakt 1 const int S2_PIN = 3; // Reedkontakt 2 const int BTN_HP0 = 4; // Taster Hp0 (Halt) const int BTN_HP1 = 5; // Taster Hp1 (Fahrt) const int BTN_HP2 = 6; // Taster Hp2 (Langsamfahrt) const int BTN_SH1 = 7; // Taster Sh1 (Rangierfahrt) const int LED_ROT1 = 8; const int LED_ROT2 = 9; const int LED_GRUEN = 10; const int LED_GELB = 11; const int LED_WEISS1 = 12; const int LED_WEISS2 = 13; enum Aspekt { HP0, HP1, HP2, SH1 }; Aspekt aktuellerAspekt = HP0; const int rundenZiel = 3; int rundenZaehler = 0; const unsigned long entprellzeit = 50; // ms const int reedPins[2] = {S1_PIN, S2_PIN}; unsigned long letzterImpulsReed[2] = {0, 0}; bool letzterZustandReed[2] = {HIGH, HIGH}; const int btnPins[4] = {BTN_HP0, BTN_HP1, BTN_HP2, BTN_SH1}; unsigned long letzterImpulsBtn[4] = {0, 0, 0, 0}; bool letzterZustandBtn[4] = {HIGH, HIGH, HIGH, HIGH}; void setup() { for (int i = 0; i < 2; i++) pinMode(reedPins[i], INPUT_PULLUP); for (int i = 0; i < 4; i++) pinMode(btnPins[i], INPUT_PULLUP); pinMode(LED_ROT1, OUTPUT); pinMode(LED_ROT2, OUTPUT); pinMode(LED_GRUEN, OUTPUT); pinMode(LED_GELB, OUTPUT); pinMode(LED_WEISS1, OUTPUT); pinMode(LED_WEISS2, OUTPUT); setAspekt(HP0); // Startzustand: Halt Serial.begin(9600); } void loop() { // Rundenzähler über beide Reedkontakte (Gruppensignal) for (int i = 0; i < 2; i++) { bool zustand = digitalRead(reedPins[i]); if (zustand == LOW && letzterZustandReed[i] == HIGH) { if (millis() - letzterImpulsReed[i] > entprellzeit) { rundenZaehler++; letzterImpulsReed[i] = millis(); Serial.print("Reed "); Serial.print(i + 1); Serial.print(" - Runde: "); Serial.println(rundenZaehler); if (rundenZaehler >= rundenZiel) { setAspekt(HP0); rundenZaehler = 0; Serial.println("3 Runden erreicht - Hp0 (Halt)"); } } } letzterZustandReed[i] = zustand; } // Manuelle Taster for (int i = 0; i < 4; i++) { bool zustand = digitalRead(btnPins[i]); if (zustand == LOW && letzterZustandBtn[i] == HIGH) { if (millis() - letzterImpulsBtn[i] > entprellzeit) { letzterImpulsBtn[i] = millis(); setAspekt((Aspekt)i); rundenZaehler = 0; // Zähler bei manuellem Wechsel zurücksetzen Serial.print("Manuell gesetzt: Aspekt "); Serial.println(i); } } letzterZustandBtn[i] = zustand; } } void setAspekt(Aspekt a) { aktuellerAspekt = a; digitalWrite(LED_ROT1, (a == HP0 || a == SH1) ? HIGH : LOW); digitalWrite(LED_ROT2, (a == HP0) ? HIGH : LOW); digitalWrite(LED_GRUEN, (a == HP1 || a == HP2) ? HIGH : LOW); digitalWrite(LED_GELB, (a == HP2) ? HIGH : LOW); digitalWrite(LED_WEISS1, (a == SH1) ? HIGH : LOW); digitalWrite(LED_WEISS2, (a == SH1) ? HIGH : LOW); }