Go Down

Topic: Analog input timer (Read 566 times) previous topic - next topic


small issue I know one of you can helo me out with very easily. If I want the code below to only work if the analogRead has been less than two for 30 seconds what do i do?
Code: [Select]
if (analogRead(0) < 2) {digitalWrite (LEDpinStat, HIGH);}


Code: [Select]

static unsigned long timerStart = 0;

if (analogRead(0) >= 2)
    timerStart = millis();

if (millis() - timerStart > 30000)
    digitalWrite (LEDpinStat, HIGH);   // A0 has been <2 for 30 seconds or more
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Coding Badly

What you are trying to do is essentially the same as debouncing a push-button.  This should get you started...

Code: [Select]
unsigned long Mark;

void loop( void )
 if (analogRead(0) >= 2)
   Mark = millis();

 if ( millis() - Mark >= 30000UL )
   // Do your thing.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131