Implementing activate and clear

This commit is contained in:
Lukas Bachschwell 2019-05-19 15:21:36 +02:00
parent 9042775f1c
commit 29ec2f7641
1 changed files with 30 additions and 12 deletions

View File

@ -8,7 +8,11 @@
#include <ETH.h> #include <ETH.h>
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; static bool eth_connected = false;
@ -98,7 +102,8 @@ void setup() {
WiFi.onEvent(WiFiEvent); WiFi.onEvent(WiFiEvent);
ETH.begin(); ETH.begin();
pinMode(5, INPUT_PULLUP); pinMode(PIN_ACTIVATE, INPUT_PULLUP);
pinMode(PIN_CLEAR, INPUT_PULLUP);
while (!eth_connected) { while (!eth_connected) {
delay(1000); delay(1000);
@ -136,21 +141,34 @@ void setup() {
void loop() { void loop() {
if (digitalRead(5) != input1active) { if (digitalRead(PIN_ACTIVATE) != inputActive) {
delay(10); delay(10);
if (digitalRead(5) != input1active) { if (digitalRead(PIN_ACTIVATE) != inputActive) {
input1active = digitalRead(5); inputActive = digitalRead(PIN_ACTIVATE);
if (!input1active) { if (!inputActive) { // React when the signal starts
Serial.println("Turn on"); if (millis() - activateTimeout >= 60000) { // 1 Minute timeout
ws.textAll("blinkLamp"); Serial.println("Activate triggered");
} else { ws.textAll("blinkLamp");
Serial.println("Turn off"); }
ws.textAll("noBlinkLamp");
} }
} }
} }
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);
} }
/////////////////////////// ///////////////////////////