Page 1 of 1

Wait until function

Posted: Wed Oct 10, 2007 4:29 pm
by echase
Is the there a ‘wait until’ function which stops the code till a defined event occurs?

e.g. for the macro

Line 1: Display a value on LCD
Do nothing and wait until any button is pressed
If any button not pressed for 5 seconds go to somewhere else/end macro.
Increment value by one if it is button A
Or decrement by 1 if button B.
Go to line 1

Only way I can think of implementing this is using a loop (instead of ‘wait until’) which runs continuously until a counter reaches a certain value. On each run through the loop the buttons are read and the value in/decremented according to any button pressed. Also a counter is incremented by one for each loop pass and is reset to zero for every button press.

If no button is pressed for 5 seconds the counter reaches the certain value so that the loop ends.

Posted: Wed Oct 10, 2007 5:04 pm
by Steve
The switches component has macros "WaitUntilLow" and "WaitUntilHigh", but these do not have a timeout.

The way you have suggested - i.e. using a loop - is one way you can do it.