From 29ec2f76414bda76a81b32a4237a7b5d7295ee97 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Sun, 19 May 2019 15:21:36 +0200 Subject: [PATCH] Implementing activate and clear --- src/controller_main.cpp | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/controller_main.cpp b/src/controller_main.cpp index 3d0d7fc..f2e7ebb 100644 --- a/src/controller_main.cpp +++ b/src/controller_main.cpp @@ -8,7 +8,11 @@ #include -bool input1active = true; +#define PIN_ACTIVATE 5 +#define PIN_CLEAR 2 +bool inputActive = true; +bool clearActive = true; +long activateTimeout = 0; static bool eth_connected = false; @@ -98,7 +102,8 @@ void setup() { WiFi.onEvent(WiFiEvent); ETH.begin(); - pinMode(5, INPUT_PULLUP); + pinMode(PIN_ACTIVATE, INPUT_PULLUP); + pinMode(PIN_CLEAR, INPUT_PULLUP); while (!eth_connected) { delay(1000); @@ -136,21 +141,34 @@ void setup() { void loop() { - if (digitalRead(5) != input1active) { + if (digitalRead(PIN_ACTIVATE) != inputActive) { delay(10); - if (digitalRead(5) != input1active) { + if (digitalRead(PIN_ACTIVATE) != inputActive) { - input1active = digitalRead(5); - if (!input1active) { - Serial.println("Turn on"); - ws.textAll("blinkLamp"); - } else { - Serial.println("Turn off"); - ws.textAll("noBlinkLamp"); + inputActive = digitalRead(PIN_ACTIVATE); + if (!inputActive) { // React when the signal starts + if (millis() - activateTimeout >= 60000) { // 1 Minute timeout + Serial.println("Activate triggered"); + ws.textAll("blinkLamp"); + } } } } - delay(100); + + if (digitalRead(PIN_CLEAR) != clearActive) { + delay(10); + if (digitalRead(PIN_CLEAR) != clearActive) { + + clearActive = digitalRead(PIN_CLEAR); + if (clearActive) { // React when the signal is over + Serial.println("Clear triggered"); + ws.textAll("noBlinkLamp"); + activateTimeout = millis(); + } + } + } + + delay(1); } ///////////////////////////