Project 12 – Piezo Sounder Melody Player
Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are going to get your Arduino to play the chorus of “Puff the Magic Dragon.” Leave the circuit exactly the same as in Project 11; you are just changing the code.
Enter the Code
Open up your Arduino IDE and type in the code from Listing 4-2.
Listing 4-2. Code for Project 12
// Project 12 - Piezo Sounder Melody Player
#define NOTE_C3 131#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277 #define ...
Get Beginning Arduino now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.