13Interrupts and Other Special Functions
Parts You'll Need for This Chapter
- Arduino Uno or Adafruit METRO 328
- USB cable (Type A to B for Uno, Type A to Micro-B for METRO)
- Half-size or full-size breadboard
- Assorted jumper wires
- Pushbutton
- 100Ω resistor
- 220Ω resistors (×3)
- 10kΩ resistor
- 5 mm Common-anode RGB LED
- 10μF 50V electrolytic capacitor
- Piezo buzzer
- 74AHCT14 hex inverting Schmitt trigger
- CODE AND DIGITAL CONTENT FOR THIS CHAPTER
- Code downloads, videos, and other digital content for this chapter can be found at:
exploringarduino.com/content2/ch13- Code for this chapter can also be obtained from the Downloads tab on this book's Wiley web page:
wiley.com/go/exploringarduino2e
Up to this point, every Arduino program you've written has been synchronous. This presents a few problems, one being that using delay() can preclude your Arduino from doing other things. There are a variety of ways to make your Arduino multitask so that you don't waste any valuable processor cycles doing nothing.
In this chapter, you will learn how to leverage both timer and hardware interrupts to make your Arduino sketches asynchronous. Interrupts make it possible to execute code asynchronously by triggering certain events (time elapsed, input state change, and so on). Interrupts, as their name implies, allow you to stop whatever your Arduino is currently doing, complete a different task, and then return to whatever command the Arduino was previously executing. You will also learn how to execute interrupts ...