If you are looking for the Chapter 2 content for the 2nd Edition of Exploring Arduino, please click here.
Digital Inputs, Outputs, and Pulse-Width Modulation
Parts List
- Arduino Uno
- USB A-B Cable
- Small Breadboard
- Jumper Wires
- 10kΩ resistor
- 220Ω resistor (x3)
- Pushbutton
- Red LED
- Common-cathode RGB LED
Code
Download Code (1st 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
Code errata listed below are corrected in the code downloads available from this page, and from github.
- In numbered list on pages 26 and 27, there should be another step between steps 1 and 2: “100 is less than or equal to 1000, so the loop contents execute.” This makes the for loop description more clear.
- In code listing 2-5, there is a missing closing bracket ( } ) following the “current = digitalRead(BUTTON);” line in early prints of the book. This has been fixed in later printings.
- In code listing 2-6, the “if” statement for Purple should be an “if else” statement.
Color Wiring Diagrams
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: