intspeakerPin=2;intlength=15;// the number of notescharnotes[]="ccggaagffeeddc ";// a space represents a restintbeats[]={1,1,1,1,1,1,2,1,1,1,1,1,1,2,4};inttempo=300;voidplayTone(inttone,intduration){for(longi=0;i<duration*1000L;i+=tone*2){digitalWrite(speakerPin,HIGH);delayMicroseconds(tone);digitalWrite(speakerPin,LOW);delayMicroseconds(tone);}}voidplayNote(charnote,intduration){charnames[]={'c','d','e','f','g','a','b','C'};inttones[]={1915,1700,1519,1432,1275,1136,1014,956};// play the tone corresponding to the note namefor(inti=0;i<8;i++){if(names[i]==note){playTone(tones[i],duration);}}}voidsetup(){pinMode(speakerPin,OUTPUT);}voidloop(){for(inti=0;i<length;i++){if(notes[i]==' '){delay(beats[i]*tempo);// rest}else{playNote(notes[i],beats[i]*tempo);}// pause between notesdelay(tempo/2);}}