#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Include the library for the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buzzerPin = 25;
int melody[] = {392, 440, 392, 349, 294, 392, 349, 294, 330, 294, 440, 392,
349, 294, 440, 392, 349, 294};
int noteDurations[] = {500, 500, 500, 750, 250, 500, 750, 250, 500, 500, 500, 500,
750, 250, 500, 500, 750, 1000};
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.print("<Instrumental>");
delay(2000);
lcd.clear();
// Initialize the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// Play each note in the melody
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
int noteDuration = noteDurations[i];
// Play the current note on the buzzer
tone(buzzerPin, melody[i], noteDuration);
// Display the frequency of the current note
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Playing Note:");
lcd.setCursor(1, 1);
lcd.print(melody[i]);
// Wait for the duration of the note
delay(noteDuration * 1.3);
// Stop the buzzer
noTone(buzzerPin);
}
// After the melody finishes, display restarting message
lcd.clear();
lcd.print("Restarting...");
delay(2000);
}