Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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...