Shop OBEX P1 Docs P2 Docs Learn Events
Question about pause command until a condition happens — Parallax Forums

Question about pause command until a condition happens

Kenm5261Kenm5261 Posts: 1
edited 2005-12-15 05:06 in BASIC Stamp
In my bs1 program, I want to pause or stop the program from looping for a 10 seconds unless an input comes on. If the input comes on i want to jump to a different routine. Can I do this??
Would it be easier to write a for loop with a counter that would check every second to see if the input has come on, then jump to the different routine?

Override:
LOW 6
Pause 10000
GOTO Main


This is the subroutine I have. I forgot that I have to check an input while its paused and if this input comes on i have to goto main. It can switch over in a second, it doesnt have to switch in a millisecond or anything.

Comments

  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-12-15 05:04
    Override:
    LOW 6
    FOR x = 1 to 10000
    IF Input = True THEN GOTO Elsewhere
    Next
    GOTO Main

    Elsewhere:

    Perform "Different routine"

    I don't know how long it would take the For Next loop to run, but this code will let you check for an input during your waiting period.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-15 05:06
    I'm not sure if this is what you're looking for but it should give you something to think about. You set a value in timer to the number of 0.1 second units you want to delay (if there is no input). The delay will happen unless the input is sensed -- the trick is that your input should be at least 100 ms long so that you can hit the input check.

    Delay:
    · IF timer = 0 THEN Delay_Exit···· ' exit if timer expired
    ··· PAUSE 100······················'·delay 0.1 sec
    ··· timer = timer - 1············· ' update timer
    ··· IF Override = No THEN Delay··· ' keep going unless override input active

    Delay_Exit:
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.