#include <WiFi.h>
#define relay 27
#define signal 5
int lightStatus = 0;
int lowTimer;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(500);
Serial.println("Serial initialized");
pinMode(relay, OUTPUT);
pinMode(signal, INPUT_PULLDOWN);
digitalWrite(relay, HIGH);
}
void loop() {
int currentStatus = digitalRead(signal);
//Serial.println(currentStatus);
if(currentStatus == 0){
lowTimer = millis();
}
if (lowTimer != 0) {
Serial.println(lowTimer);
}
lowTimer = 0;
if (currentStatus == 0 && lightStatus == 0) {
digitalWrite(relay, HIGH);
Serial.println("LED is ON");
lightStatus = 1;
currentStatus = 1;
delay(1000);
} else if (currentStatus == 0 && lightStatus == 1) {
digitalWrite(relay, LOW);
Serial.println("LED is OFF");
lightStatus = 0;
currentStatus = 1;
delay(1000);
}
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
}