Just think about what you need to do and program accordingly...
Rule 1. Increment a variable 1-10 if a Button is pressed.
Rule 2. This variable loops back to 1 if value 10 is exceeded.
Rule 3. Timeout and exit if Button has not been pressed for 5 Seconds.
Code:MyButton var PortB.0 ' Pin goes LOW when Button pressed MyNumber var Byte ' Variable 1-10 MyTimeOut var Byte ' 5 second Timeout (100 loops of 50mS) MyNumber=1 ' Power-On with this starting value MyTimeOut=0 ' TimeOut starts from zero at Power-Up While MyTimeOut<100 If MyButton=0 then MyNumber=MyNumber+1 If MyNumber>10 then MyNumber=1 MyTimeOut=0 Pause 50 ' This Pause DEBOUNCES Button - do not remove it While MyButton=0:Wend ' Wait here if Button held down else MyTimeOut=MyTimeOut+1 Pause 50 ' This Pause is the Timeout Pause endif Wend




Bookmarks