#include <Arduino.h>
#define BUZZER_PIN 12 // pino conectado ao buzzer
int melody[] = {
659, 659, 659, 523, 587, 523, 659, 659,
659, 698, 784, 784, 698, 659, 587, 523,
659, 659, 659, 523, 587, 523, 659, 659,
659, 698, 784, 784, 698, 659, 587, 523
};
int note_durations[] = {
4, 4, 2, 2, 2, 1, 4, 4,
4, 4, 2, 2, 2, 1, 4, 4,
4, 4, 2, 2, 2, 1, 4, 4,
4, 4, 2, 2, 2, 1, 4, 4
};
void playNote(int frequency, int duration) {
tone(BUZZER_PIN, frequency, duration);
delay(duration);
}
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
for (int i = 0; i < sizeof(melody)/sizeof(int); i++) {
playNote(melody[i], 1000/note_durations[i]);
delay(10);
}
}