Shop OBEX P1 Docs P2 Docs Learn Events
Need help with debouncing a pair of switches. — Parallax Forums

Need help with debouncing a pair of switches.

ihmechihmech Posts: 179
edited 2010-05-31 02:24 in BASIC Stamp
I'm having trouble figuring out how to debounce a pair of switches I added to a project.· I only had two pins left (pin2 and pin3).· I know how to debounce 4 or 8 switches, but not 2.· It seems to be eluding me.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-30 20:10
    Debouncing 2 switches is not particularly different from debouncing 1 or 4 or 8 switches. The easy way to do it with Stamps is to use the BUTTON statement which takes care of debouncing for you. The main thing you want to do is, when you sense that a switch has closed, you want to wait a little while and check again to make sure that the switch is still closed. If the switch has remained closed over a period of time (100ms or so), you can trust that it really is closed. If the switch isn't still closed, you start over again.

    What you can do is have two nibble counters, one for each switch. If a switch is open, you set its counter to zero. If a switch is closed, you increment its counter unless it's already 15. You do this in a loop that pauses for 10ms each time through the loop. If either counter goes from 14 to 15, that switch has become closed.
  • ihmechihmech Posts: 179
    edited 2010-05-31 02:24
    Thanks Mike!

    I was able to get it figured out. It wasn't as hard as I thought. Its amazing how some of the simple solutions can be the hardest to figure out!
Sign In or Register to comment.