Dealing with pushbuttons, debouncing etc...

My laser harp has 2 buttons to control parameters - one button selects the parameter and the other selects the value. It works ok, but I found I had to put 1 second delays after pushing buttons to deal with multiple-presses and debouncing etc...

Is there a library, or preferred way to deal with buttons? As what I've done is very clunky...

One second is a bit long - I usually use 20 -> 25ms for debounce time.

How you implement this depends on how you structure your application. In my case, I usually have a loop that runs periodically. On the Arduino, I've been using 1ms as its easy to generate. Then I would use a state machine and a down counter for the buttons.

Make any sense?


If you really want to fully understand debouncing and the various solutions, the ultimate reference is . It covers almost every aspect. If you just want some quick ideas, skip down to p17 where it talks about software solutions.

50ms is usually "fast enough" for user input.


PS: a general purpose switch debouncing routine would make an excellent playground article. [hint, hint]

Thanks for the input - that's great