main cleanup
This commit is contained in:
parent
43497376cb
commit
f1e5a758c2
@ -1,668 +1,15 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "CMainController.h"
|
||||||
|
|
||||||
//Pindefinitionen
|
CMainController controller;
|
||||||
#define LED_ANLAGE_EIN_AUS 2
|
|
||||||
#define KNOPF_ANLAGE_EIN_AUS 3
|
|
||||||
|
|
||||||
#define LED_STATION_BESETZT_UNBESETZT 4
|
void setup()
|
||||||
#define KNOPF_STATION_BESETZT_UNBESETZT 5
|
|
||||||
|
|
||||||
#define LED_SERVICEBETRIEB 6
|
|
||||||
#define KNOPF_SERVICEBETRIEB 7
|
|
||||||
|
|
||||||
#define LED_FAHRGASTBETRIEB 22
|
|
||||||
#define KNOPF_FAHRGASTBETRIEB 23
|
|
||||||
|
|
||||||
#define LED_ROT_EREIGNISANZEIGE 13
|
|
||||||
#define LED_GELB_EREIGNISANZEIGE 12
|
|
||||||
#define LED_GRUEN_EREIGNISANZEIGE 11
|
|
||||||
|
|
||||||
#define LED_QUIT_BETRIEB 9
|
|
||||||
#define KNOPF_QUIT_BETRIEB 10
|
|
||||||
|
|
||||||
#define LED_START_BETRIEB 36
|
|
||||||
#define KNOPF_START_BETRIEB 37
|
|
||||||
|
|
||||||
#define LED_HALT 38
|
|
||||||
#define KNOPF_HALT 39
|
|
||||||
|
|
||||||
#define LED_NOTHALT 40
|
|
||||||
#define KNOPF_NOTHALT 41
|
|
||||||
|
|
||||||
#define LED_VORWAERTS 30
|
|
||||||
#define KNOPF_VORWAERTS 31
|
|
||||||
|
|
||||||
#define LED_RUECKWAERTS 32
|
|
||||||
#define KNOPF_RUECKWAERTS 33
|
|
||||||
|
|
||||||
// Hilfsvariablen zum merken des Zustands
|
|
||||||
bool buttonStateAnlageEinAus = false;
|
|
||||||
bool currentButtonStateAnlageEinAus = false;
|
|
||||||
|
|
||||||
bool buttonStateStationBesetztUnbesetzt = false;
|
|
||||||
bool currentButtonStateStationBesetztUnbesetzt = false;
|
|
||||||
|
|
||||||
bool buttonStateServicebetrieb = false;
|
|
||||||
bool currentButtonStateServicebetrieb = false;
|
|
||||||
|
|
||||||
bool buttonStateFahrgastbetrieb = false;
|
|
||||||
bool currentButtonStateFahrgastbetrieb = false;
|
|
||||||
|
|
||||||
bool buttonStateQuitBetrieb = false;
|
|
||||||
bool currentButtonStateQuitBetrieb = false;
|
|
||||||
|
|
||||||
bool buttonStateStart = false;
|
|
||||||
bool currentButtonStateStart = false;
|
|
||||||
|
|
||||||
bool buttonStateHalt = false;
|
|
||||||
bool currentButtonStateHalt = false;
|
|
||||||
|
|
||||||
bool buttonStateNothalt = false;
|
|
||||||
bool currentButtonStateNothalt = false;
|
|
||||||
|
|
||||||
bool buttonStateVorwaerts = false;
|
|
||||||
bool currentButtonStateVorwaerts = false;
|
|
||||||
|
|
||||||
bool buttonStateRueckwaerts = false;
|
|
||||||
bool currentButtonStateRueckwaerts = false;
|
|
||||||
|
|
||||||
// Anlagenzustände
|
|
||||||
enum
|
|
||||||
{
|
{
|
||||||
AUS,
|
|
||||||
SERVICE_QUITTIEREN,
|
|
||||||
SERVICE,
|
|
||||||
FAHRGAST_QUITTIEREN,
|
|
||||||
FAHRGAST,
|
|
||||||
} anlagenzustand;
|
|
||||||
|
|
||||||
// Fahrtrichtungen
|
|
||||||
enum Fahrtrichtung
|
|
||||||
{
|
|
||||||
HALT, // Anlage steht
|
|
||||||
NOTHALT, // Anlage steht (Notstop)
|
|
||||||
VORWAERTS_QUITTIEREN, // Richtungsknopf vorwärts gedrückt, warte auf quittieren
|
|
||||||
WARTE_START_VORWAERTS, // Anlage steht und wartet auf starten (in die entsprechende Richtung)
|
|
||||||
VORWAERTS, // Anlage fährt vorwärts
|
|
||||||
RUECKWAERTS_QUITTIEREN, // Richtungsknopf rückwärts gedrückt, warte auf quittieren
|
|
||||||
WARTE_START_RUECKWAERTS, // Anlage steht und wartet auf starten (in die entsprechende Richtung)
|
|
||||||
RUECKWAERTS, // Anlage fährt rückwärts
|
|
||||||
} fahrtrichtung;
|
|
||||||
|
|
||||||
Fahrtrichtung vorherigeRichtung = HALT;
|
|
||||||
|
|
||||||
void quittierenButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Quittieren Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateQuitBetrieb && !buttonStateQuitBetrieb)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateQuitBetrieb == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
switch(fahrtrichtung)
|
|
||||||
{
|
|
||||||
case HALT:
|
|
||||||
case NOTHALT:
|
|
||||||
if(vorherigeRichtung == RUECKWAERTS)
|
|
||||||
{
|
|
||||||
fahrtrichtung = WARTE_START_RUECKWAERTS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fahrtrichtung = WARTE_START_VORWAERTS;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VORWAERTS_QUITTIEREN:
|
|
||||||
fahrtrichtung = WARTE_START_VORWAERTS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RUECKWAERTS_QUITTIEREN:
|
|
||||||
fahrtrichtung = WARTE_START_RUECKWAERTS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateQuitBetrieb = currentButtonStateQuitBetrieb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void startButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Start Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateStart = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateStart && !buttonStateStart)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateStart = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateStart == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
switch(fahrtrichtung)
|
|
||||||
{
|
|
||||||
case WARTE_START_VORWAERTS:
|
|
||||||
fahrtrichtung = VORWAERTS;
|
|
||||||
vorherigeRichtung = VORWAERTS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WARTE_START_RUECKWAERTS:
|
|
||||||
fahrtrichtung = RUECKWAERTS;
|
|
||||||
vorherigeRichtung = RUECKWAERTS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateStart = currentButtonStateStart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FERTIG
|
|
||||||
void haltButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Start Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateHalt = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateHalt && !buttonStateHalt)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateHalt = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateHalt == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
fahrtrichtung = HALT;
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateHalt = currentButtonStateHalt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FERTIG
|
|
||||||
void nothaltButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Start Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateNothalt = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateNothalt && !buttonStateNothalt)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateNothalt = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateNothalt == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
fahrtrichtung = NOTHALT;
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateNothalt = currentButtonStateNothalt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FERTIG
|
|
||||||
void vorwaertsButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Start Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateVorwaerts = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateVorwaerts && !buttonStateVorwaerts)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateVorwaerts = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateVorwaerts == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
// In jeder beliebigen Fahrtrichtung, Fahrtrichtung Ändern (HALT, NOTHALT, RUECKWAERTS_QUITTIEREN, )
|
|
||||||
fahrtrichtung = VORWAERTS_QUITTIEREN;
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateVorwaerts = currentButtonStateVorwaerts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FERTIG
|
|
||||||
void rueckwaertsButtonAbfragen()
|
|
||||||
{
|
|
||||||
// ========== Start Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateRueckwaerts = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateRueckwaerts && !buttonStateRueckwaerts)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateRueckwaerts = digitalRead(KNOPF_START_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateRueckwaerts == LOW)
|
|
||||||
{
|
|
||||||
// Knopf gedrückt => Code ausführen
|
|
||||||
// ============================================================
|
|
||||||
fahrtrichtung = RUECKWAERTS_QUITTIEREN;
|
|
||||||
// ============================================================
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateRueckwaerts = currentButtonStateRueckwaerts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
anlagenzustand = AUS;
|
|
||||||
fahrtrichtung = HALT;
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
controller.setup();
|
||||||
// Pindefinitonen
|
|
||||||
pinMode(LED_ANLAGE_EIN_AUS, OUTPUT);
|
|
||||||
pinMode(KNOPF_ANLAGE_EIN_AUS, INPUT_PULLUP);
|
|
||||||
|
|
||||||
pinMode(LED_STATION_BESETZT_UNBESETZT, OUTPUT);
|
|
||||||
pinMode(KNOPF_STATION_BESETZT_UNBESETZT, INPUT_PULLUP);
|
|
||||||
|
|
||||||
pinMode(LED_SERVICEBETRIEB, OUTPUT);
|
|
||||||
pinMode(KNOPF_SERVICEBETRIEB, INPUT_PULLUP);
|
|
||||||
|
|
||||||
pinMode(LED_FAHRGASTBETRIEB, OUTPUT);
|
|
||||||
pinMode(KNOPF_FAHRGASTBETRIEB, INPUT_PULLUP);
|
|
||||||
|
|
||||||
pinMode(LED_QUIT_BETRIEB, OUTPUT);
|
|
||||||
pinMode(KNOPF_QUIT_BETRIEB, INPUT_PULLUP);
|
|
||||||
|
|
||||||
pinMode(LED_ROT_EREIGNISANZEIGE, OUTPUT);
|
|
||||||
pinMode(LED_GELB_EREIGNISANZEIGE, OUTPUT);
|
|
||||||
pinMode(LED_GRUEN_EREIGNISANZEIGE, OUTPUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
switch(anlagenzustand)
|
|
||||||
{
|
{
|
||||||
// #################### Anlage ausgeschaltet
|
controller.work();
|
||||||
case AUS:
|
|
||||||
{
|
|
||||||
// ========== LEDs entsprechend des Zustands setzen
|
|
||||||
digitalWrite(LED_ANLAGE_EIN_AUS, LOW);
|
|
||||||
digitalWrite(LED_STATION_BESETZT_UNBESETZT, LOW);
|
|
||||||
digitalWrite(LED_SERVICEBETRIEB, LOW);
|
|
||||||
digitalWrite(LED_FAHRGASTBETRIEB, LOW);
|
|
||||||
digitalWrite(LED_ROT_EREIGNISANZEIGE, LOW);
|
|
||||||
digitalWrite(LED_GELB_EREIGNISANZEIGE, LOW);
|
|
||||||
digitalWrite(LED_GRUEN_EREIGNISANZEIGE, LOW);
|
|
||||||
digitalWrite(LED_QUIT_BETRIEB, LOW);
|
|
||||||
|
|
||||||
// ========== Ein/Aus Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateAnlageEinAus && !buttonStateAnlageEinAus)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateAnlageEinAus == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "SERVICE" versetzen und damit starten
|
|
||||||
anlagenzustand = SERVICE;
|
|
||||||
digitalWrite(LED_ANLAGE_EIN_AUS, HIGH);
|
|
||||||
digitalWrite(LED_STATION_BESETZT_UNBESETZT, HIGH);
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateAnlageEinAus = currentButtonStateAnlageEinAus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #################### Anlage im Service-quittieren Zustand
|
|
||||||
// Anlage wechselt in den Servicezustand, sobald der Zustandswechsel durch den Nutzer quittiert wird
|
|
||||||
case SERVICE_QUITTIEREN:
|
|
||||||
{
|
|
||||||
// ========== LEDs entsprechend des Zustands setzen
|
|
||||||
digitalWrite(LED_QUIT_BETRIEB, HIGH);
|
|
||||||
digitalWrite(LED_GELB_EREIGNISANZEIGE, HIGH);
|
|
||||||
digitalWrite(LED_GRUEN_EREIGNISANZEIGE, LOW);
|
|
||||||
|
|
||||||
// ========== Ein/Aus Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateAnlageEinAus && !buttonStateAnlageEinAus)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateAnlageEinAus == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "AUS" versetzen und damit stoppen
|
|
||||||
anlagenzustand = AUS;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateAnlageEinAus = currentButtonStateAnlageEinAus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Quittieren Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateQuitBetrieb && !buttonStateQuitBetrieb)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateQuitBetrieb == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "SERVICE" versetzen
|
|
||||||
anlagenzustand = SERVICE;
|
|
||||||
digitalWrite(LED_QUIT_BETRIEB, LOW);
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateQuitBetrieb = currentButtonStateQuitBetrieb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #################### Anlage im Servicezustand
|
|
||||||
case SERVICE:
|
|
||||||
{
|
|
||||||
// ========== LEDs entsprechend des Zustands setzen
|
|
||||||
digitalWrite(LED_SERVICEBETRIEB, HIGH);
|
|
||||||
digitalWrite(LED_FAHRGASTBETRIEB, LOW);
|
|
||||||
digitalWrite(LED_ROT_EREIGNISANZEIGE, HIGH);
|
|
||||||
digitalWrite(LED_GELB_EREIGNISANZEIGE, LOW);
|
|
||||||
digitalWrite(LED_GRUEN_EREIGNISANZEIGE, LOW);
|
|
||||||
|
|
||||||
// ========== Fahrtrichtungsabhängige Steuerung
|
|
||||||
switch(fahrtrichtung)
|
|
||||||
{
|
|
||||||
// Anlage steht
|
|
||||||
case HALT:
|
|
||||||
{
|
|
||||||
quittierenButtonAbfragen(); // => "WARTE_START" Anhand Richtung
|
|
||||||
vorwaertsButtonAbfragen(); // => "VORWAERTS_QUITTIEREN"
|
|
||||||
rueckwaertsButtonAbfragen(); // => "RUECKWAERTS_QUITTIEREN"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Anlage steht
|
|
||||||
case NOTHALT:
|
|
||||||
{
|
|
||||||
quittierenButtonAbfragen(); // => "WARTE_START"
|
|
||||||
vorwaertsButtonAbfragen(); // => "VORWAERTS_QUITTIEREN"
|
|
||||||
rueckwaertsButtonAbfragen(); // => "RUECKWAERTS_QUITTIEREN"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Anlage steht
|
|
||||||
|
|
||||||
|
|
||||||
// Anlage fährt vorwärts
|
|
||||||
case VORWAERTS_QUITTIEREN:
|
|
||||||
{
|
|
||||||
quittierenButtonAbfragen(); // => "WARTE_START_VORWAERTS"
|
|
||||||
haltButtonAbfragen(); // => "HALT"
|
|
||||||
nothaltButtonAbfragen(); // => "NOTHALT"
|
|
||||||
rueckwaertsButtonAbfragen(); // => "RUECKWAERTS_QUITTIEREN"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WARTE_START_VORWAERTS:
|
|
||||||
{
|
|
||||||
startButtonAbfragen(); // => "VORWAERTS"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Anlage fährt vorwärts
|
|
||||||
case VORWAERTS:
|
|
||||||
{
|
|
||||||
haltButtonAbfragen(); // => "HALT"
|
|
||||||
nothaltButtonAbfragen(); // => "NOTHALT"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Anlage fährt rückwärts
|
|
||||||
case RUECKWAERTS_QUITTIEREN:
|
|
||||||
{
|
|
||||||
quittierenButtonAbfragen(); // => "WARTE_START_RUECKWAERTS"
|
|
||||||
haltButtonAbfragen(); // => "HALT"
|
|
||||||
nothaltButtonAbfragen(); // => "NOTHALT"
|
|
||||||
vorwaertsButtonAbfragen(); // => "VORWAERTS_QUITTIEREN"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WARTE_START_RUECKWAERTS:
|
|
||||||
{
|
|
||||||
startButtonAbfragen(); // => "RUECKWAERTS"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Anlage fährt rückwärts
|
|
||||||
case RUECKWAERTS:
|
|
||||||
{
|
|
||||||
haltButtonAbfragen(); // => "HALT"
|
|
||||||
nothaltButtonAbfragen(); // => "NOTHALT"
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Ein/Aus Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateAnlageEinAus && !buttonStateAnlageEinAus)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateAnlageEinAus == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "AUS" versetzen und damit stoppen
|
|
||||||
anlagenzustand = AUS;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateAnlageEinAus = currentButtonStateAnlageEinAus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Fahrgast Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateFahrgastbetrieb = digitalRead(KNOPF_FAHRGASTBETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateFahrgastbetrieb && !buttonStateFahrgastbetrieb)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateFahrgastbetrieb = digitalRead(KNOPF_FAHRGASTBETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateFahrgastbetrieb == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "SERVICE_QUITTIEREN" versetzen
|
|
||||||
anlagenzustand = SERVICE_QUITTIEREN;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateFahrgastbetrieb = currentButtonStateFahrgastbetrieb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #################### Anlage im Fahrgast-quittieren Zustand
|
|
||||||
// Anlage wechselt in den Fahrgastzustand, sobald der Zustandswechsel durch den Nutzer quittiert wird
|
|
||||||
case FAHRGAST_QUITTIEREN:
|
|
||||||
{
|
|
||||||
// ========== LEDs entsprechend des Zustands setzen
|
|
||||||
digitalWrite(LED_QUIT_BETRIEB, HIGH);
|
|
||||||
digitalWrite(LED_GELB_EREIGNISANZEIGE, HIGH);
|
|
||||||
digitalWrite(LED_ROT_EREIGNISANZEIGE, LOW);
|
|
||||||
|
|
||||||
// ========== Ein/Aus Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateAnlageEinAus && !buttonStateAnlageEinAus)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateAnlageEinAus == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "AUS" versetzen und damit stoppen
|
|
||||||
anlagenzustand = AUS;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateAnlageEinAus = currentButtonStateAnlageEinAus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Quittieren Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateQuitBetrieb && !buttonStateQuitBetrieb)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateQuitBetrieb = digitalRead(KNOPF_QUIT_BETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateQuitBetrieb == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "SERVICE" versetzen
|
|
||||||
anlagenzustand = SERVICE;
|
|
||||||
digitalWrite(LED_QUIT_BETRIEB, LOW);
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateQuitBetrieb = currentButtonStateQuitBetrieb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #################### Anlage im Fahrgastzustand
|
|
||||||
case FAHRGAST:
|
|
||||||
{
|
|
||||||
// ========== LEDs entsprechend des Zustands setzen
|
|
||||||
digitalWrite(LED_SERVICEBETRIEB, LOW);
|
|
||||||
digitalWrite(LED_FAHRGASTBETRIEB, HIGH);
|
|
||||||
digitalWrite(LED_GRUEN_EREIGNISANZEIGE, HIGH);
|
|
||||||
digitalWrite(LED_GELB_EREIGNISANZEIGE, LOW);
|
|
||||||
|
|
||||||
// ========== Fahrtrichtungsabhängige Steuerung
|
|
||||||
// switch(fahrtrichtung)
|
|
||||||
// {
|
|
||||||
// // Anlage steht
|
|
||||||
// case HALT:
|
|
||||||
// {
|
|
||||||
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// // Anlage fährt vorwärts
|
|
||||||
// case VORWAERTS:
|
|
||||||
// {
|
|
||||||
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// // Anlage fährt rückwärts
|
|
||||||
// case RUECKWAERTS:
|
|
||||||
// {
|
|
||||||
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// default:
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ========== Vorwärts Button abfragen
|
|
||||||
vorwaertsButtonAbfragen();
|
|
||||||
|
|
||||||
// ========== Ein/Aus Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateAnlageEinAus && !buttonStateAnlageEinAus)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateAnlageEinAus = digitalRead(KNOPF_ANLAGE_EIN_AUS) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateAnlageEinAus == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "AUS" versetzen und damit stoppen
|
|
||||||
anlagenzustand = AUS;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateAnlageEinAus = currentButtonStateAnlageEinAus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Service Button abfragen
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateServicebetrieb = digitalRead(KNOPF_SERVICEBETRIEB) == LOW;
|
|
||||||
// Aktuellen Zustand mit vorherigem vergleichen
|
|
||||||
if (currentButtonStateServicebetrieb && !buttonStateServicebetrieb)
|
|
||||||
{
|
|
||||||
// Warten zum entprellen
|
|
||||||
delay(20);
|
|
||||||
// Taster abfragen und aktuellen Zustand zwischenspeichern
|
|
||||||
currentButtonStateServicebetrieb = digitalRead(KNOPF_SERVICEBETRIEB) == LOW;
|
|
||||||
// Prüfen ob immernoch gedrückt
|
|
||||||
if (currentButtonStateServicebetrieb == LOW)
|
|
||||||
{
|
|
||||||
// Anlage in den Zustand "SERVICE_QUITTIEREN" versetzen
|
|
||||||
anlagenzustand = SERVICE_QUITTIEREN;
|
|
||||||
// Speichern des ButtonStates als Vergleichswert für den nächsten Durchlauf
|
|
||||||
buttonStateServicebetrieb = currentButtonStateServicebetrieb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ####################
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user