Shop OBEX P1 Docs P2 Docs Learn Events
input debounce — Parallax Forums

input debounce

ArchiverArchiver Posts: 46,084
edited 2002-07-31 19:52 in General Discussion
I have written some code for a BS2 that looks at pins 0-2 for a low
input. Once a pin goes low e.g. IF INP0=0 THEN *** (via a Happ button
push)then the code makes the device look at pins 3-5 for another low
input (via a Happ button push). Ultimately, I plan to use a BS2P and
utilize 12 inputs pins and 12 output pins.

I programmed my BS2 and have it working just fine on my proto board.
I was wondering if I should go ahead and debounce the inputs. I would
rather do this with code rather than external logic device(s).

Can anybody recommend the easiest/simple way to do this in code?

Thanks,
Guy

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-07-31 19:52
    A simple loop is all it takes to debounce multiple inputs. Here's a bit of
    code that I routinely use in my projects. It can be adapted for any number
    of inputs.

    The routine is setup for active low switches, hence the tilde (invert)
    operator used with InA (change this part as needed). The routine assumes
    that all buttons are pressed. It scans the inputs then ANDs them with the
    assumed state. If any input goes (or is) inactive, even momentarily, then it
    will return as not pressed.

    You can fine-tune the debounce period by changing the loop count and the loop
    delay.

    Get_Switches:
    switches = %1111
    FOR x = 1 TO 10
    switches = switches & ~InA
    PAUSE 5
    NEXT
    RETURN

    -- Jon Williams
    -- Parallax

    In a message dated 7/31/02 1:28:41 PM Central Daylight Time, guyb@m...
    writes:


    > I have written some code for a BS2 that looks at pins 0-2 for a low
    > input. Once a pin goes low e.g. IF INP0=0 THEN *** (via a Happ button
    > push)then the code makes the device look at pins 3-5 for another low
    > input (via a Happ button push). Ultimately, I plan to use a BS2P and
    > utilize 12 inputs pins and 12 output pins.
    >
    > I programmed my BS2 and have it working just fine on my proto board.
    > I was wondering if I should go ahead and debounce the inputs. I would
    > rather do this with code rather than external logic device(s).
    >
    > Can anybody recommend the easiest/simple way to do this in code?
    >
    > Thanks,
    > Guy
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.