Go Down

Topic: Wait for input (Read 593 times) previous topic - next topic

Chimaera

Mar 26, 2012, 12:07 pm Last Edit: Mar 26, 2012, 12:12 pm by Chimaera Reason: 1
Hi there,

I have small programming problem which is quite easy to solve i guess - I just don't know how. In fact i want to programm a menu through which is navigated with an rotary encoder. This menu shall be in a subfunction which is activated by a button.

Now my problem is, that I don't know how a "wait order" is implemented:
The idea is, that the programm waits for maybe 10 seconds to get an input signal (which is then once again the rotary encoder for choosing an  option or the button then to select it) or, if no signal is detected, then jumps back to the main function.

I guess i can't use the delay order since then the whole programm is being made to wait and it won't accept any input signals in the mean time.



PaulS

Quote
I guess i can't use the delay order since then the whole programm is being made to wait and it won't accept any input signals in the mean time.

You guess correctly. You can implement a while loop, and use millis().

Code: [Select]
unsigned long startTime = millis();
while(millis() - startTime < interval)
{
   // check for input. Break if found
}
// When we get here, either there was input or the time expired.

Chimaera

Thank you. That helped a lot. ;-)

Go Up