Digital Inputs, Outputs, and Pulse-Width Modulation
This chapter covered the following concepts:
- How a breadboard works
- How to pick a resistor to current-limit an LED
- How to wire an external LED to your Arduino
- How to use PWM to write “analog” values to LEDs
- How to read a pushbutton
- How to debounce a pushbutton
- How to use for loops
- How to utilize pullup and pulldown resistors
- Arduino Uno
- USB A-B Cable
- Small Breadboard
- Jumper Wires
- 10kΩ resistor
- 220Ω resistor (x3)
- Red LED
- Common-cathode RGB LED
- 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
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
This video will teach you about digital inputs/outputs, debouncing, and PWM:
This video will teach you the basics of electrical and computer engineering:
All code is licensed via the GNU GPL v3. Code is maintained and updated on GitHub. The download zip linked above always contains the most recent version of the code examples that have been pushed to the GitHub Code Repository.