Implementing activate and clear

This commit is contained in:
Lukas Bachschwell 2019-05-19 15:21:36 +02:00
parent 9042775f1c
commit 29ec2f7641

View File

@ -8,7 +8,11 @@
#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;
@ -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");
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");
} else {
Serial.println("Turn off");
}
}
}
}
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(100);
delay(1);
}
///////////////////////////