If you are looking for the Chapter 2 content for the 1st Edition of Exploring Arduino, please click here.
Digital Inputs, Outputs, and Pulse-Width Modulation
Parts List
- 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
- 220Ω resistors (×3)
- 10kΩ resistor
- 5mm red LED
- 5mm common-anode RGB LED
Code
Download Code (2nd Edition, Chapter 2)
(Also available on GitHub)
Useful Links
- Arduino setup() Reference Page
- Arduino loop() Reference Page
- Arduino pinMode() Reference Page
- Arduino digitalWrite() Reference Page
- Arduino analogWrite() Reference Page
- Arduino constants Reference Page
- Arduino for loop Reference Page
- Arduino delay() Reference Page
- Arduino digitalRead() Reference Page
- Arduino if/else Reference Page
Errata
- On page 46, the final else{} statement in listing 2-6 (rgb_nightlight.ino) for the RGB nightlight is supposed to turn the nightlight off. Because the RGB LED is common anode, this should be done by setting all the cathode pins HIGH, but the printed code sets them all LOW by mistake. This issue has been resolved in the downloadable code for this chapter. (GitHub Issue Details)
- On page 46, the closing curly bracket is missing from the loop() function of code listing 2-6 (rgb_nightlight.ino). The downloadable code correctly includes the missing bracket – the issue is only in print.
Videos
This video will teach you about digital inputs/outputs, debouncing, and PWM:
This video will teach you the basics of electrical and computer engineering: