Happy Birthday to You - Code Song
The classic “Happy Birthday” song written in code. We recommend that you’ve followed the projects up to at least speaker project 8 so you’ll have an understanding of how this song is coded with variables. Start here and tinker, modify, and update to make your own version or your own completely new song!
//'Happy Birthday To You'
int C = 523;
int D = 587;
int E = 659;
int F = 699;
int G = 784;
int A = 880;
int bFlat = 932;
int highC = 1074;
/*C,C,D,C,F,E
  C,C,D,C,G,F
  C,C,highC,A,F,F,E,D
  B-flat,B-flat,highA,F,G,F
*/
int note = 480; //how long each note plays
void setup(){ 
    pinMode(10,OUTPUT); //Set the Speaker as an OUTPUT
}
void loop(){
    //First Line
    tone(10,C);
    delay(note/3);
    noTone(10); //Pause between two strikes of the same note sounds like a separate keystroke
    delay(20);
    
    tone(10,C);
    delay(note/2);
    
    tone(10,D);
    delay(note);
    tone(10,C);
    delay(note);
    tone(10,F);
    delay(note);
    tone(10,E);
    delay(note);
    
    noTone(10);
    delay(800);
    
    //Second Line
    tone(10,C);
    delay(note/3);
    noTone(10); //Pause between two strikes of the same note sounds like a separate keystroke
    delay(20);
    
    tone(10,C);
    delay(note/2);
    tone(10,D);
    delay(note);
    tone(10,C);
    delay(note);
    tone(10,G);
    delay(note);
    tone(10,F);
    delay(note);
    
    noTone(10);
    delay(800);
    
    //Third Line
    tone(10,C);
    delay(note/3);
    noTone(10); //Pause between two strikes of the same note sounds like a separate keystroke
    delay(20);
    
    tone(10,C);
    delay(note/2);
    
    tone(10,highC);
    delay(note);
    tone(10,A);
    delay(note);
    
    tone(10,F);
    delay(note/2);
    noTone(10); //Pause between two strikes of the same note sounds like a separate keystroke
    delay(20);
    
    tone(10,F);
    delay(note);
    
    tone(10,E);
    delay(note);
    
    tone(10,D);
    delay(note);
    
    noTone(10);
    delay(800);
    
    //Fourth Line
    tone(10,bFlat);
    delay(note/2);
    noTone(10); //Pause between two strikes of the same note sounds like a separate keystroke
    delay(20);
    
    tone(10,bFlat);
    delay(note);
    
    tone(10,A);
    delay(note);
    
    tone(10,F);
    delay(note);
    
    tone(10,G);
    delay(note);
    
    tone(10,F);
    delay(note);
    
    noTone(10);
    delay(5000); //wait 5 seconds before replaying the song
    
}
// (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
	
			Heads up! You need our Chrome App to run this code.
			
		
	Success!
	Compile errors:
	
		Serial port monitor:
		
			Input: 
			
			
		
	
	
