const float GAMMA = 0.7;
const float RL10 = 50;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
pinMode(13, INPUT);
pinMode(12, INPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
int val = digitalRead(13);
int value = analogRead(A0);
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
// Handle traffic light sequence without delay
if (currentMillis - previousMillis >= interval && lux < 50 && val == HIGH)
{
previousMillis = currentMillis;
digitalWrite(12,HIGH);
}else if(currentMillis - previousMillis >= interval){
digitalWrite(12,LOW);
}
}