Debouncing

A common problem when dealing with switches and electronics is how to handle the contact bouncing. When you press the switch, there will be due to the mechanical design of the switch, a short bouncing of the switch before it stabilizes. It depends on how you read of the switch but normally this will lead to unwanted effects, like counting the button multiple times even though the user only presses once. There are a few tricks how to solve it but when I was looking on the Internet for inspiration, I stubbled up on an article written by Jack Ganssle. It is the best summary I have read about contact bouncing and is worth a few minutes of your time.

I also found one of his algorithms implemented by tcleg in a very portable way and nicely licensed. This is the library I use for the game console and it works very well! Highly recommended!