Start Switch
I have a program that uses a DO LOOP to call subroutines, the problem I have is I want a switch when turned On it will start·the DO LOOP and when turned off will stop the program.
Example of code
DO
GoSUB 1
GoSub 2
GoSub 3
Loop
Post Edited (bennettdan) : 5/4/2006 7:45:19 AM GMT
Example of code
DO
GoSUB 1
GoSub 2
GoSub 3
Loop
Post Edited (bennettdan) : 5/4/2006 7:45:19 AM GMT
Comments
begin:
debug "Press any key to start", cr
debugin com
go to start
start:
DO/Loop
As for stopping, find where you want to stop, then write:
serin pin, baud, 100, cont, [noparse][[/noparse]com]
goto begin
cont: 'continue with program
The serin will wait 100ms for an input.· If it gets nothing it will jump to cont and continue the program.· If it gets something it will go back to begin.· The 100 can be adjusted to whatever length of time your program can handle.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
LOOP UNTIL IN(0) = 0
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
LOOP WHILE IN0 = 11
then DO.......
LOOP WHILE IN0 = 0
If he throws his switch so IN0 = 1, then IN0 will still be 1 after the third GOSUB and the loop will shut down after one cycle.· I suppose if he was using a pushbutton and pushed it very quickly the loop would start and if he let go of the button before the third GOSUB ended then the loop would continue running.· If he pushes the button to stop it it is going to start over unless he is very quick.
Sid
·· If you read the original post you would see that I mentioned if you have an active LOW switch connected.· This means the OPEN state of the switch will be 1 per the pull-up resistor.· When the switch is CLOSED (turned on) the signal will be LOW and the code will dropw through into the DO...LOOP.· At this point the switch is still in a 0 state...And the code says to LOOP WHILE in that state.· When the switch is turned off (opened) it will go HIGH again and the program will end.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com