Hardware Reference
In-Depth Information
Figure 5-3: Arduino IDE with a secondary header file
Click the pitches.h tab to see the contents of the file. Notice that it's just a list
of definition statements, which map human-readable names to given frequency
values. Simply having the header file in the IDE does not suffice, though. To
ensure that the compiler actually uses those definitions when compiling your
program for the Arduino, you need to tell the compiler to look for that file. Doing
so is easy. Just add this line of code to the top of your .ino file:
#include "pitches.h" //Header file with pitch definitions
To the compiler, this is essentially the same thing as copying and pasting the
contents of the header file into the top of your main file. However, this keeps
the file neater and easier for you to read. In the next sections, you write the code
for the rest of this file so that you can actually use the pitch definitions that you
have just imported.
WiringtheSpeaker
Now that you have your pitches header file included, you're ready to build a test
circuit and to write a simple program that can play some music. The electrical
setup is fairly simple and just involves hooking up a speaker to an output pin
of your Arduino. However, remember what you've learned in previous chapters
about current-limiting resistors.
Just as with LEDs, you want to put a current-limiting resistor in series with
the speaker to ensure that you don't try to draw too much current from one of
the Arduino's I/O pins. As you learned previously, each I/O pin can supply only
a max of 40mA, so pick a resistor that prevents you from exceeding that. The
Search WWH ::




Custom Search