BUTTON Command
byoc
Posts: 17
I'm trying to make a simple pushbutton tactile switch that turns an LED on with one press and turns it off with another press. It's sort of working. The "*" in the debug window comes up everytime the button is pressed, but the LED does not turn on/off reliably. Sometimes it takes two or three pushes for it to work. Here's my code:
' {$STAMP BS2}
' {$PBASIC 2.5}
Btn PIN 3
btnWrk VAR Byte
TurnOn:
BUTTON Btn, 0, 255, 255, btnWrk , 0, PressOn
DEBUG "*"
HIGH 14
PressOn:
GOTO TurnOff
TurnOff:
BUTTON Btn, 0, 255, 255, btnWrk, 0, PressOff
DEBUG "*"
LOW 14
PressOff:
GOTO TurnOn
Any ideas as to what I'm doing wrong?
' {$STAMP BS2}
' {$PBASIC 2.5}
Btn PIN 3
btnWrk VAR Byte
TurnOn:
BUTTON Btn, 0, 255, 255, btnWrk , 0, PressOn
DEBUG "*"
HIGH 14
PressOn:
GOTO TurnOff
TurnOff:
BUTTON Btn, 0, 255, 255, btnWrk, 0, PressOff
DEBUG "*"
LOW 14
PressOff:
GOTO TurnOn
Any ideas as to what I'm doing wrong?
Comments
Btn PIN 3
btnWrk VAR Byte
Main:
BUTTON Btn, 0, 255, 255, btnWrk , 0, No_Press
TOGGLE 14
No_Press:
GOTO Main
Although, your way will make more sense when I use it in a practical application because ultimately I want it to do more than just turn the LED on and off.