Hardware Reference
In-Depth Information
Figure 12-9: Sound machine wiring diagram
SoundMachineSoftware
The software for the sound machine utilizes software and hardware interrupts
in addition to serial communication and tone() to control a speaker. Load the
code from Listing 12-3 on to your Arduino and press the button on the bread-
board to cycle through base frequencies. You can open the serial monitor to see
the frequency currently playing.
Listing 12-3: Sound Machine Code—fun_with_sound.ino
//Use Hardware and Timer Interrupts for Fun with Sound
//Include the TimerOne library
#include <TimerOne.h>
//Button pins
const int BUTTON_INT =0; //Interrupt 0 (pin 2 on the Uno)
const int SPEAKER =12; //Speaker on pin 12
//Music keys
#define NOTE_C 65
#define NOTE_D 73
#define NOTE_E 82
#define NOTE_F 87
Search WWH ::




Custom Search