View Full Version : Need help with Button command

01-20-2007, 01:33 AM
I am using a BS2 and trying to use the button command to detect different pushbutton switch closures. The switches are wired for active low, ie. normally pulled hi when not pressed. Here is a snipet of my main loop:

BUTTON Btn1, 0, 255, 250, btnWrk, 1, Backlight
BUTTON Btn2, 0, 255, 250, btnWrk, 1, DisplayMode
loopcount = loopcount + 1
GOSUB Read_0834
IF loopcount = 10 THEN
loopcount = 0
GOTO Update_display

When I press button1, the Backlight code toggles the display backlight. The description of the button command seems to indicate that when the delay parameter is 255, then no autorepeat will occur (the autorepeat parameter should have no effect). What I see is as long as I hold the button pressed, the code continuously branches to the address specified with the cycle time of the main loop, approx. 1 second. I was expecting, and need, a routine that will only branch once if the button is held down, and will not reset/rearm until the button is released.

Any suggestions??

Thanks, Glenn

Tracy Allen
01-20-2007, 02:36 AM
You need to use a separate btnWrk for each button.

I don't recommend using the BUTTON command unless you really do need the autorepeat. There are more economical ways to do simple debouncing, so that the workspace is only one bit instead of a whole byte. There is an analysis of the BUTTON command and alternatives on my web site at,

Tracy Allen
www.emesystems.com (http://www.emesystems.com)