#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0X27,16,2);
#define BUZZER_PIN 23 // Adjust this pin based on your setup
#define BUTTON_PIN 2
const int buzzerPin = 23;
int inpin=2;
const int songLength = 73;
const int songLengthDeckTheHalls = 73;
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
char notesDeckTheHalls[] = "gfedcdecdefdedcoc gfedcdecdefdedcoc defdefgeefgabCbag gfedcdecdefdedcoc ";
//gfedcdecdefdedcoc gfedcdecdefdedcoc
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int beatsDeckTheHalls[] = {3,1,2,2,2,2,2,2,1,1,1,1,3,1,2,2,3,1,3,1,2,2,2,2,2,2,1,1,1,1,3,1,2,2,3,1,3,1,2,2,3,1,2,2,1,1,2,1,1,2,2,2,3,1,3,1,2,2,2,2,2,2,1,1,1,1,3,1,2,2,3,};
int tempo = 150;
const char *lyrics[] = {
"Deck the halls",
"with boughs of holly",
"Fa-la-la-la-la,",
"la-la-la-la",
"Tis the season",
"to be jolly",
"Fa-la-la-la-la,",
"la-la-la-la",
"Don we now",
"our gay apparel",
"Fa-la-la-la-la,",
"la-la-la-la",
"Troll the ancient ",
"Yule-tide carol",
"Fa-la-la-la-la,",
"la-la-la-la",
};
// Add more lyrics as needed
const char delimiter = ';';
void setup() {
lcd.init();
lcd.begin(20,4);
pinMode(buzzerPin, OUTPUT);
lcd.setCursor(0,0);
delay(1000);
pinMode(BUTTON_PIN, INPUT_PULLUP);
debouncer.attach(BUTTON_PIN);
debouncer.interval(50);
}
void loop() {
debouncer.update();
if (debouncer.fell()) {
displayLyricsAndBuzzer();
}
lcd.setCursor(0,0);
lcd.println(
"Deck the halls"
"with boughs of holly"
"Fa la la la"
"la la la la");
delay(1000);
if (digitalRead(inpin)==HIGH)
{
play_music();
}
};
void play_music()
{
int i, duration;
for (i = 0; i < songLengthDeckTheHalls; i++)
{
duration = beatsDeckTheHalls[i] * tempo;
if (notesDeckTheHalls[i] == ' ')
{
delay(duration);
}
else
{
tone(buzzerPin, frequency(notesDeckTheHalls[i]), duration);
delay(duration);
}
delay(tempo/10);
}
}
int frequency(char note)
{
int i;
const int numNotes = 9;
char names[] = { 'o','c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {247,262, 294, 330, 349, 392, 440, 494, 523};
for (i = 0; i < numNotes; i++)
{
if (names[i] == note)
{
return(frequencies[i]);
}
}
return(0);
}
//#define NOTE_B3 247