THERE ARE LOTS of ways to make code control things in the real world. You have already controlled movement with motors and controlled light with LEDs. In this adventure you’re going to create sound!
In Adventures 3 and 4, you discover some new ways to make your code more efficient when you need to repeat the instructions more than once. The
for loop is a great tool for repeating something a set number of times. When you combine a
for loop with special lists in code—called arrays—you end up with a powerful coding tool.
After learning how to harness the power of arrays and figuring out how to get your Arduino to sing to you, you’re going to put your new skills into practice by building an augmented wind chime that plays both acoustic and electronic sounds.
What You Need
You need a few things for the first part of this chapter (the electronic components are shown in Figure 5-1):
- A computer
- An Arduino Uno
- A USB cable
- A breadboard
- 7 jumper wires
- 6 LEDs
- 6 220Ω resistors
- A piezo
Making a List
Variables are useful ways of keeping track of information like the numbers of the pins on your Arduino Uno. Creating a variable to store the number of the pin to which a particular LED is connected makes your ...