Hello, i’m having a problem with this code. Actually i want to read an analogRead in 3 seconds with a photoresistor, but it didn’t work. I connected the photoresistor to A0 pin, also a led connected a led to simulate this code that blink every 3 sec. Please correct my code below if i missed something or wrong.
pinMode( LED, OUTPUT );
boolean analogAboveThreshold(int pin, unsigned long millisec, int threshold)
unsigned long start = millis();
while (analogRead(pin) >= threshold); // blocking !!
unsigned long duration = millis() - start;
return ( abs(duration - millisec) <= 100 );
if (analogAboveThreshold(A0, 3000, 500) )
digitalWrite(13,LOW);// yes we have ~3 seconds high
anyway thank you