header
Play Sounds

Play tones out of a speaker.

picture of board with parts schematic

/*
  play_sounds
*/

int speaker = 9;
// Some notes to use
int G = 392;
int C = 523;
int E = 659;
int F = 698;
int G2 = 784;

void setup() {
  pinMode(speaker, OUTPUT);

  // Just play song once in setup.  To repeat move it to loop()
  tone(speaker, G);
  delay(200);
  tone(speaker, C);
  delay(200);
  tone(speaker, E);
  delay(200);
  tone(speaker, G2);
  delay(300);
  noTone(speaker);
  delay(100);
  tone(speaker, E);
  delay(200);
  tone(speaker, G2);
  delay(600);
  noTone(speaker);
  delay(1000);
}

void loop() {
}