Waiting for input
Hello!
How can I program this situation?
"If button is pressed whitin 5 seconds, jump to some sort of label."
anybody knows?
How can I program this situation?
"If button is pressed whitin 5 seconds, jump to some sort of label."
anybody knows?
Comments
The PBASIC Stamp does not have any interrupt capability, nor is there an accessable RTC. however, if you can use SERIN to field your input SERIN permits a "timeout label" to be used. If you were using (say) a PBASIC Stamp BS-2 you'd set the Timeout value to 5000 mS (5 seconds) and place an appropriate label in the Tlabel field.
Alternatively, you can certainly add an inexpensive RTC with an alarm feature, and poll it to see if 5 seconds has expired.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
LedEvent:
LED = 1
For Counter = 1 to 50
Counter = Counter + 1
Pause 100
If Button = 1 then ButtonPressed
Next
Goto Main
ButtonPressed:
'do some stuff here
LedEvent:
LED = 1
Counter = 0 'reset counter which has byte value variable
For Counter = 1 to 500
Counter = Counter + 1
Pause 10 'may not be precisely 5 seconds, check and adjust as needed
If Button = 1 then ButtonPressed
Next
Goto Main
ButtonPressed:
'do some stuff here
This version looks at the button with 10 times more resolution, or 5000 : 1 (1 being a millisecond)