Timer
weizenheimer37
Posts: 2
I am looking for a way to time out a command. I have my code waiting for IN4 to return true, and then continue on with my code. I want my code to be able to keep track of how long it waits for IN4 to return true, and move on to the future code if IN4 never returns true after a specified amount of time (about 6 seconds). Is there any way that I can do this? I am coding in pBasic 2.5, and using the BS2p Stamp. I just started working with this stuff a couple of weeks ago, and this is the one thing I have not been able to figure out. Any help would be awesome! Thanks.
Comments
The way this is often done is to test IN4. If false, the program pauses for some specific time (like 10ms), then checks again while keeping a count of the number of times the program has PAUSEd. When that count exceeds some value (like 600), the program has timed out and goes to do somethine else.
You can also try this demo as well I have used this a few time and works very well
' {$STAMP BS2}
' {$PBASIC 2.5}
Chg··· PIN··· 0
cntr·· VAR··· Word
· cntr = 0
· DO
··· ' do other loop stuff
··· cntr = cntr + 1 * Chg············ 'If input stays HIGH· then EXIT
··· IF (cntr = 300) THEN EXIT·······' This controls for how long it looks at a input to see if it says true
· LOOP
' With the BS2 you can have parenthesis in an expression so the (1 - Chg)
' part inverts that value.
·cntr = 0
· DO
··· ' do other loop stuff
··· cntr = cntr + 1 * (1 - Chg)······· 'If input stays LOW then EXIT
··· IF (cntr = 300) THEN EXIT········ ' This controls for how long it looks at a input to see if it says true
· LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam