Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Button command — Parallax Forums

Need help with Button command

glennwglennw Posts: 8
edited 2007-01-19 19:36 in BASIC Stamp
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:

Main:
PAUSE 100
BUTTON Btn1, 0, 255, 250, btnWrk, 1, Backlight
BUTTON Btn2, 0, 255, 250, btnWrk, 1, DisplayMode
button_return:
loopcount = loopcount + 1
GOSUB Read_0834
IF loopcount = 10 THEN
loopcount = 0
GOTO Update_display
ENDIF
GOTO Main

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

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2007-01-19 19:36
    Glenn,
    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,
    [noparse][[/noparse]ur]http://www.emesystems.com/BS2fsm.htm#BUTTON

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.