BS2 Wait for Input from PushButton
Jeff_5_
Posts: 36
I'm working on writing a program that uses a slide switch and a push button. I want the switch to take me in or out of the loop and the push button to go to the next step of the loop.
It will work like this.
Turn switch on to get into loop
Then do some code
Then wait for push button to be pressed or for switch to go off
If push button pressed go to next step for more code. If switch turned off exit the loop.
Switch is on input pin 5 Push button on input pin 6
IF(IN5= 1)THEN Says switch is on go starts loop
Do some code
Now wait for (IN5=0) or (IN6=1)
If (IN5=0) then exit loop
If (IN6=1) Then go to next step
Do some code
Now again wait for (IN5=0) or (IN6=1)
If (IN5=0) then exit loop
If (IN6=1) Then go to next step
How can i get the program to stop and wait for a button press or the switch to go off?
Thanks
It will work like this.
Turn switch on to get into loop
Then do some code
Then wait for push button to be pressed or for switch to go off
If push button pressed go to next step for more code. If switch turned off exit the loop.
Switch is on input pin 5 Push button on input pin 6
IF(IN5= 1)THEN Says switch is on go starts loop
Do some code
Now wait for (IN5=0) or (IN6=1)
If (IN5=0) then exit loop
If (IN6=1) Then go to next step
Do some code
Now again wait for (IN5=0) or (IN6=1)
If (IN5=0) then exit loop
If (IN6=1) Then go to next step
How can i get the program to stop and wait for a button press or the switch to go off?
Thanks
Comments
a:if IN6=1 then b' pushbutton pressed, jump ahead to b and continue
if IN5=1 then c ' switch closed, jump to c and continue
goto a ' neither pressed, go back to a
b: yada yada yada
...
...
(skip around c if necessary)
c: yada yada
...
...
DO WHILE IN5 = 0
IF IN6 = 1 THEN
Do Some Code
ENDIF
LOOP
' This creates a loop that will continue to run until IN5 is pressed, exiting the loop.
' While inside the loop, it will wait for IN6 to be pressed.
' If IN6 is pressed, then it will do some code (this is a good place for a GOSUB command).
' If IN6 is not pressed, then it will just return to the beginning of the loop.
Another useful tool is a "Latch"
DO UNTIL IN5=1 OR IN6=1
LOOP
' This will effectively halt the program by forcing it to run in very tiny circles until you do something.
I use both of these with three pushbuttons on my clock project:
http://forums.parallax.com/showthread.php?133886-Six-Digits-of-Doom