#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ================= PIN =================
#define BUZZER_PIN 18
#define RED_PIN 25
#define GREEN_PIN 26
#define BLUE_PIN 27
// ================= PWM =================
#define PWM_RES 8 // 0–255
// ================= TEMPO =================
float speedFactor = 0.45;
// ================= MELODY =================
int melody[] = {
264, 264, 297, 264, 352, 330,
264, 264, 297, 264, 396, 352,
264, 264, 528, 440, 352, 330, 297,
466, 466, 440, 352, 396, 352
};
int durations[] = {
250, 250, 500, 500, 500, 1000,
250, 250, 500, 500, 500, 1000,
250, 250, 500, 500, 500, 500, 1000,
250, 250, 500, 500, 500, 1000
};
String nama = "Anggela Fera T.A.";
// ================= RGB =================
void setRGB(int r, int g, int b) {
ledcWrite(RED_PIN, r);
ledcWrite(GREEN_PIN, g);
ledcWrite(BLUE_PIN, b);
}
// ================= MUSIC + RGB SYNC =================
void playBirthday() {
for (int i = 0; i < 25; i++) {
int dur = durations[i] * speedFactor;
int nada = melody[i];
int bright = map(nada, 200, 600, 80, 255);
bright = constrain(bright, 80, 255);
if (nada < 300) {
setRGB(bright, 0, 0); // MERAH
} else if (nada < 400) {
setRGB(0, bright, 0); // HIJAU
} else {
setRGB(0, 0, bright); // BIRU
}
ledcWriteTone(BUZZER_PIN, nada);
delay(dur);
ledcWriteTone(BUZZER_PIN, 0);
setRGB(0, 0, 0);
delay(40);
}
}
// ================= LCD =================
void tampilPesan(String atas, String bawah, int waktu) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(atas);
lcd.setCursor(0, 1);
lcd.print(bawah);
delay(waktu);
}
// ================= COUNTDOWN =================
void hitungMundur() {
for (int i = 3; i > 0; i--) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HITUNG MUNDUR");
lcd.setCursor(7, 1);
lcd.print(i);
setRGB(255, 255, 255);
ledcWriteTone(BUZZER_PIN, 1000);
delay(300);
ledcWriteTone(BUZZER_PIN, 0);
setRGB(0, 0, 0);
delay(700);
}
}
// ================= SETUP =================
void setup() {
lcd.init();
lcd.backlight();
// Attach PWM (API BARU)
ledcAttach(BUZZER_PIN, 2000, PWM_RES);
ledcAttach(RED_PIN, 5000, PWM_RES);
ledcAttach(GREEN_PIN, 5000, PWM_RES);
ledcAttach(BLUE_PIN, 5000, PWM_RES);
hitungMundur();
tampilPesan("HAPPY BIRTHDAY", nama, 3000);
playBirthday();
tampilPesan("SUDAH 23 TAHUN", "WANITA HEBATKUU", 3000);
tampilPesan("KUAT, PINTAR", "& TANGGUHH", 3000);
tampilPesan("SEMANGAT TERUS", "SAYANGKUU", 3000);
tampilPesan("AKU BANGGA", "PADAMUU <3", 4000);
}
void loop() {}