How often does an arduino check a value

I’m trying to get an if statement to happen if the potentiometer has moved while the delay is happening. So the delay could be happening, I’d move the potentiometer all the way to the other side and my if statement if(potvalue != 0) won’t happen. Have I missed a step?

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

if (potvalue == 0) // starts at 0
{
digitalWrite(waitLED, HIGH);
digitalWrite(redLED, LOW);
digitalWrite(goLED, LOW);
digitalWrite(piezo, LOW);
digitalWrite(LEDA, LOW);
digitalWrite(LEDB, LOW);
digitalWrite(LEDC, LOW);
delay(2000);
if (digitalRead(PBA) == LOW && digitalRead(PBB) == LOW && digitalRead(PBC) == LOW) // tests if the gray code signal has been sent
{
digitalWrite(goLED, HIGH); // correct gray code signal has been sent
digitalWrite(waitLED, LOW);
delay(2000);
if (potvalue != 0)
{
digitalWrite(waitLED, HIGH);
digitalWrite(redLED, HIGH);
digitalWrite(goLED, HIGH);
delay(5000);
}

delay() stops everything happening so you cannot read an input. You need to use a different strategy to wait for a period and do something else at the same time

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

To answer the question in your title: it checks it whenever you put something in your code to check it. The loop() function unencumbered by delays and blocking code will go around maybe 10000 or 100000 times in 1 second, that’s how often a check would happen.

Put a 3 second delay in and the answer becomes every 3 seconds (or longer).

Please post your code as per the instructions for a better answer.

[Edit]
When I started typing your code wasn’t there…

And now the code is there but posted without code tags

Never by itself. Always only if you do so in the code.

I think we are missing the point of the question. @gunny98 is not asking how to check the potentiometer value while the delay is running; he wants the delay to run, and then check the potentiometer to see if it has been moved during the delay period.

He seems to have made a simple mistake: he is reading potvalue to see if it has changed, but presumably potvalue requires an analogRead() to update it. So there is his problem: he hasn’t updated potvalue with an analogRead(). Once that is sorted out the problem he asks about should go away.

Whether this is good programming practice is another question, of course.

I suspect the same. But since he doesn’t show the whole code, we can only guess.

1 Like