Timing and debouncing

If you play a little with the previous circuit once programmed, you can easily conclude that the reaction to the button press is not immediate, and it is due to the fact that in the code, the button press is only read once the reaction, blinking or fading, has concluded and both of them take their time, even if short.

In Chapter 9, Dealing with Interrupts, we will see another way to react immediately to these kinds of events through the use of a very powerful procedure called interrupts.

There is another final consideration with respect to this example that is called debouncing, and that is due to the physical way in which electrical contacts are made when pressing a button.

Although it's hard to imagine, when you press a button, the state oscillates between on and off before the contact settles down, which can lead to incorrect readings of a sensor in the code.

You can learn more about switches and debouncing them on the Wikipedia page for switches at http://en.wikipedia.org/wiki/Switch.

The Arduino site also has a very interesting page exclusively dedicated to buttons debouncing at http://arduino.cc/en/pmwiki.php?n=Tutorial/Debounce, which deserves a reading.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset