#define LDR_PIN 2
#define RLY_PIN 3
int lightState = 0;
unsigned long timer = 0;
unsigned long lastMillis = 0;
void setup() {
// put your setup code here, to run once:
pinMode(LDR_PIN, INPUT);
pinMode(RLY_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("System begin");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10);
int lux = 5;
if (lux < 6) {
// if timer done, dim
// if (motion)
// timer start
// Full
// else
// Dim
} else {
// 0%
}
int ldrState = digitalRead(LDR_PIN);
digitalWrite(RLY_PIN, lightState);
if (ldrState == HIGH) {
lightState = 0;
timer = 0;
} else {
lightState = 1;
}
// Timer
if (millis() - lastMillis > 1000) {
lastMillis = millis();
Serial.println("tick");
if (lightState == 1) {
Serial.println("Light: ON | " + String(timer) + "/1500");
if (timer == 25 * 60) {
lightState = 0;
Serial.println("Time out, light turned off.");
}
timer += 1;
}
} else {
}
}