I'm trying to play a song through a piezo buzzer, it worked before but after I added more notes and code it stopped working.
void play( char note, int beats)
{
int numNotes = 19; // number of notes in our note and frequency array (there are 15 values, but arrays start at 0)
//Note: these notes are C major (there are no sharps or flats)
//this array is used to look up the notes
char notes[] = { "b2", 'c', "c#", 'd', 'e', 'f', "gb", 'g', "ab", 'a', "bb", 'b', 'C', "Db", 'D', 'E', 'F', 'G', 'A', 'B', ' '};
//this array matches frequencies with each letter (e.g. the 4th note is 'f', the 4th frequency is 175)
int frequencies[] = {123.5, 131, 138.59, 147, 165, 175, 185, 196, 207.65, 220, 233, 247, 262, 277.18, 294, 330, 349, 392, 440, 494, 0};
int currentFrequency = 0; //the frequency that we find when we look up a frequency in the arrays
int beatLength = 150; //the length of one beat (changing this will speed up or slow down the tempo of the song)
//look up the frequency that corresponds to the note
for (int i = 0; i < numNotes; i++) // check each value in notes from 0 to 14
{
if (notes[i] == note) // does the letter passed to the play function match the letter in the array?
{
currentFrequency = frequencies[i]; // Yes! Set the current frequency to match that note
}
}
//play the frequency that matched our letter for the number of beats passed to the play function
tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats* beatLength); //wait for the length of the tone so that it has time to play
delay(50); //a little delay between the notes makes the song sound more natural
}
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:uno -build-cache /tmp -build-path /tmp/825536684/build -verbose -libraries /tmp/825536684/custom -libraries /tmp/825536684/pinned /tmp/825536684/sketch_oct24a
Compiling sketch...
/tmp/825536684/sketch_oct24a/sketch_oct24a.ino: In function 'void play(char, int)':
/tmp/825536684/sketch_oct24a/sketch_oct24a.ino:121:128: error: too many initializers for 'char []'
exit status 1