Thanks for the response, I am still a little confused though…does this code snippet basically do what you are suggesting? This code should toggle the state of an LED when I press the switch and not be effected if the switch is held down.
Code:
SW var GPIO.1
LED1 var GPIO.2
OnOff var bit
Swset var bit
Startup:
Led1=0
OnOff=0
GOTO Main
Main:
…….
…..do regular code stuff
……
if OnOFF=1 then
led1=1
else
led1=0
endif
GOSUB Debounce:
GOTO Main
Debounce:
If SW=0 then
Swset=0 ;used to determine if switch is held down
RETURN ;if switch is not pressed return to main
Endif
If swset=1 then RETURN ;this returns to the main loop if SW is held down
If SW=1 then PAUSEUS 100 ;if switch is pressed pause 100us
IF SW=0 then RETRN ;if switch is now not pressed return to main
IF SW=1 then
OnOff=OnOff+1 ;if switch is still pressed toggle OnOff
Swset=1 ;used to determine if switch is held down
Endif
RETURN
Bookmarks