Using PWM pins with the Piezo element
Piezo elements can be really fun—you can use them to simply add music to your Johnny-Five projects. We're going to build a small project and play with some of the Johnny-Five utilities to make music with this fun little component.
Setting up the hardware
Wiring a Piezo is pretty straightforward—you need to determine the + and - sides first. Usually, the + side is marked on the top of the plastic casing of the Piezo, and one leg is longer—much like an LED, the longer leg denotes the + side. Finally, some Piezo buzzers come with lead wires that are red (the + side) and black (the - side).
Once you've determined the + side, wire it to pin 3, and wire the - side to GND, as shown in the following diagram:
Writing the script
The script is a little more complicated than our last few scripts; we need to create a Piezo element, which just requires a pin. However, a piece of music is more complicated than turning...