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?
if (analogRead(0) < 2) {digitalWrite (LEDpinStat, HIGH);}
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?
if (analogRead(0) < 2) {digitalWrite (LEDpinStat, HIGH);}
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
What you are trying to do is essentially the same as debouncing a push-button. This should get you started...
unsigned long Mark;
void loop( void )
{
if (analogRead(0) >= 2)
{
Mark = millis();
}
if ( millis() - Mark >= 30000UL )
{
// Do your thing.
}
}