Shop OBEX P1 Docs P2 Docs Learn Events
E-stop — Parallax Forums

E-stop

Frank123Frank123 Posts: 4
edited 2014-02-21 07:45 in BASIC Stamp
Hello,
I have a question in reference to the Basic 1 or 2. What I need to do is if in2 =0 then it should run the scan program but if in 3 = 0 then I want the scan program to stop and then perform the dial progam. Below is the code but when input 3 is detected the scan progam continues to run.
Check:
If in 2 = 0 then scan
If in 3= 0 then Dial
goto check

Scan:

High 4
pause 100
low 4
pause 100
high 5
pause 100
low 5
goto Check

Dial:
low 4
low5
pause 10
High 6
pause 100
low 6
goto Check

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2014-02-21 07:45
    First of all, it's "in2", not "in 2". The pauses will interfere with the program's checks for in2 and in3 since, when the Stamp is doing its pause, it's doing nothing else ... not checking in2 or in3. That may not be what you want.

    The way you've written your program, it checks for in2 first and executes Scan, then goes back and checks first for in2 again. Only if in2 is high does it even check in3. You have to release in2 first before pressing in3. If you want in2 and in3 to have a different priority, you can swap the two if statements so the test for in3 comes first. If you want some other kind of behavior, you'll have to describe more thoroughly just what behavior you want. You may need to create what's called a state machine ... in this case more than one loop where the program sits. Look up "state machine" in the Wikipedia.
Sign In or Register to comment.