O'Reilly logo

Arduino For Dummies by John Nussey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required