Chapter 11

Getting Clever with Code

In This Chapter

arrow Understanding timers

arrow Debouncing your buttons

arrow Getting more from your buttons

arrow Averaging your results

arrow Adjusting the sensitivity of sensors

As you find different uses and needs for Arduino, you can refine your code to make it more accurate, responsive, and efficient. Also, by thinking about the code in your project, you may be able to avoid or minimize many of the unexpected results that can occur when dealing with physical hardware and the real world. In this chapter, you look at a few sketches that will help you fine-tune your project.

Blinking Better

Blink is most likely the first sketch you encountered. It’s a magical moment when that first LED lights up, isn’t it? But what if I told you it that it can get even better? The basic blink sketch presented in Chapter 4 performs its task well, with one significant drawback: It can’t do anything else while blinking.

Take a look at it again:

/*

  Blink

  Turns on an LED on for one second, ...

Get Arduino For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.