Learning Examples | Foundations | Hacking | Links
Examples > Digital I/O
This example shows how to use the tone() command to generate different pitches depending on which sensor is pressed.
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic:
click the image to enlarge
The sketch below reads three analog sensors. Each corresponds to a note value in an array of notes. IF any of the sensors is above a given threshold, the corresponding note is played.
The sketch uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes.
To make this file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this:

The paste in the following code:
Here's the main sketch: