I'm trying to make a program to play Jingle bells, but it doesn't recognize the variable 'song'. Attached is a picture of the code. Any help is appreciated, thanks!
here is the code:
const int piezoPin = 2 ;
void playSong(char songname){
int duration = 26;
int notes[]={261,294,329,349,392,440,493,523};
char notenames[]={'c','d','e','f','g','a','b','C'};
if(songname == "JingleBells"){
char song[]={'e','e','e','e','e','e','e','g','c','d','e',' ','f','f','f','f','f','e','e','e','e','d','d','e','d','g'};
int beat[]={1,2,1,1,2,1,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,};
int tempo = 300;}
int x = 0;
int y = 0;
while (x < 26){
if (song[x] == notenames[y]){
tone(piezoPin,notes[y],beat[x]*tempo);
x++;
y=0;
}
else{
y++;
}
}
void setup{
pinMode(piezoPin,OUTPUT);
}
void loop{
playSong("JingleBells")
}
the error is: " 'song' was not declared in this scope"