Shop OBEX P1 Docs P2 Docs Learn Events
Problems with button input — Parallax Forums

Problems with button input

DuctapemasterDuctapemaster Posts: 90
edited 2007-06-06 05:35 in General Discussion
I am working on a simple clock for the SX and I am having problem with button inputs. In simple terms, the program is much to fast to register a 'human speed' button push as one button push. Is there some way I can implement a 'one shot' into my design without an external chip? I need the circuit to be as small as possible, so avoiding extra chips would be preferable.

I attached my code so you can see whats going on...

Thanks,

Dan

Comments

  • BeanBean Posts: 8,129
    edited 2007-06-05 11:59
    Dan,
    · You just need to wait until the button is released before continuing. Something like:
    setmin:
    if rb.0 = 1 then        'minute set routine
      inc oneminutes
      pause 10 ' debounce
      do
      loop until rb.0 = 0
    endif
     
    sethr:
    if rb.1 = 1 then        'hour set routine
      inc onehours
      pause 10 ' debounce
      do
      loop until rb.1 = 0
    endif 
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • DuctapemasterDuctapemaster Posts: 90
    edited 2007-06-05 14:32
    The only problem with that is the program stops outputting data to the display while it's waiting for the button to be released.· I think I can just make the program pass by the 'inc setminutes/sethours' if the button is released.· I will try it out this afternoon and let you know what happens.
  • JonnyMacJonnyMac Posts: 8,940
    edited 2007-06-05 14:33
    I use Bean's style as well; and if you want to be able to press-and-hold then use a larger PAUSE value (like 200) and remove the DO-LOOP that forces the button release.

    If you move your display updating into the ISR then you won't have any problems there. You can find examples of this in the help file and in my January Nuts & Volts column (download from Parallax).

    http://www.parallax.com/dl/docs/cols/nv/vol8/col/nv141.pdf

    Post Edited (JonnyMac) : 6/5/2007 2:37:56 PM GMT
  • DuctapemasterDuctapemaster Posts: 90
    edited 2007-06-06 05:35
    Well, it got it working. I had some extra code in there (I didn't need the LOOKDOWN command at all, it was redundant) so I cleaned it up a bit and put the multiplexing routine inside the ISR. It works pretty well so far and I am putting it through an all night test tonight. I just set the clock and I will see if the time is off at all in the morning. I had to change the resistor values on the pins for the display from 390 ohms to 120 ohms for the brighness to be at the level it was before. The display was originally multiplexed much slower than it was now, making the display brighter, and now it refreshes the display 200 times a second.

    Thanks for the code snippets; I implemented them and they work perfectly.

    Thanks for all the help. I will let you know tomorrow how the test went.

    -Dan
Sign In or Register to comment.