// Define the note frequencies for "Happy Birthday"
int melody[] = {
261, 261, 293, 261, 349, 329,
261, 261, 293, 261, 392, 349,
261, 261, 523, 440, 349, 329, 293,
466, 466, 440, 349, 392, 349
};
int noteDurations[] = {
4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4, 4, 2
};
void setup() {
// No setup is needed for this simple example
}
void loop() {
// Iterate through the melody
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
int noteDuration = 1000 / noteDurations[i];
tone(16, melody[i], noteDuration);
// Pause between notes
delay(noteDuration * 1.30);
// Stop the tone
noTone(16);
}
// Repeat the melody
delay(2000);
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
bz1:1
bz1:2
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL