Pages: [1]   Go Down
Author Topic: Wait for input  (Read 526 times)
0 Members and 1 Guest are viewing this topic.
Tübingen, BW, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


« Last Edit: March 26, 2012, 05:12:49 am by Chimaera » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50362
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Tübingen, BW, Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. That helped a lot. ;-)
Logged

Pages: [1]   Go Up
Jump to: