Chapter 10

Getting Clever with Code

IN THIS CHAPTER

check Understanding timers

check Debouncing your buttons

check Getting more from your buttons

check Averaging your results

check 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 that it can get even better? The basic Blink sketch presented in Chapter 3 performs its task well, with one significant drawback: It can’t do anything else while blinking.

Take a look at the Blink sketch again:

void setup() {

// initialize digital ...

Get Arduino For Dummies, 2nd Edition 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.