Shop OBEX P1 Docs P2 Docs Learn Events
Code Help Please -- Counting Button Presses — Parallax Forums

Code Help Please -- Counting Button Presses

dk_akjdk_akj Posts: 37
edited 2004-08-18 19:46 in BASIC Stamp
Hi,

This code gives me trouble.

It is supposed to count how many times pin 4 goes high.

FOR i = 1 TO 4
· DEBUG "press button x times" , DEC i,CR,LF
· COUNT 4, 25000, m_PulseCount
· DEBUG "got " , DEC m_PulseCount,CR,LF
NEXT

It counts, but it counts way to many, if i press the button 4 times it counts 8 or 10.

I have a 10K pulldown resistor on pin 4.

Can it be the button bounching ? It is the printbutton that i gor with my education board.

What can I do to solve my problem ??

//akj

Post Edited By Moderator (Jon Williams) : 8/17/2004 8:39:43 PM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-08-17 20:11
    It sounds like contact bounce is your problem...If you're trying to COUNT pulses from a mechanical device such as a pushbutton, you may want to use the BUTTON command instead.· It handles debounce, and even repeat.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    ·
  • Tracy AllenTracy Allen Posts: 6,657
    edited 2004-08-17 21:48
    Or add an RC circuit in parallel with your switch, say C=0.1uf. That should absorb the bounce. You might have to increase the value of your pulldown resistor to 49k or 100k.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dk_akjdk_akj Posts: 37
    edited 2004-08-18 06:36
    Thanks.

    I'll try that.

    //akj
  • dk_akjdk_akj Posts: 37
    edited 2004-08-18 19:46
    Thanks,

    Now it works
    I'm using the button function.

    //Akj
Sign In or Register to comment.