ArduinoArduino UnoExact chip

Melody

tone() on pin 8 plays a scale. Turn the sound on to hear it.

Melody in Argynix Lab

The code

sketch.inoC++
// tone() on pin 8: a scale, then a rest. Turn the sound on to hear it.

const int BUZZER = 8;
const int notes[] = { 262, 294, 330, 349, 392, 440, 494, 523 };

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (int i = 0; i < 8; i++) {
    tone(BUZZER, notes[i], 180);
    Serial.print("Note ");
    Serial.println(notes[i]);
    delay(220);
  }
  noTone(BUZZER);
  delay(1000);
}