#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Tone.h"
// Pin untuk buzzer
#define BUZZER_PIN 13
// OLED display setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Notasi untuk lagu "Happy Birthday"
int melody[] = {
NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_F4, NOTE_E4, // bar 1
NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_G4, NOTE_F4, // bar 2
NOTE_C4, NOTE_C4, NOTE_C5, NOTE_A4, NOTE_F4, NOTE_E4, NOTE_D4, // bar 3
NOTE_AS4, NOTE_AS4, NOTE_A4, NOTE_F4, NOTE_G4, NOTE_F4 // bar 4
};
int noteDurations[] = {
4, 4, 4, 4, 4, 4, // bar 1
4, 4, 4, 4, 4, 4, // bar 2
4, 4, 4, 4, 4, 4, 4, // bar 3
4, 4, 4, 4, 4, 4 // bar 4
};
// Gambar bitmap placeholder (Smiley face 8x8)
const uint8_t birthday_image_bits[] PROGMEM = {
0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C // Gambar smiley
};
// Fungsi untuk memainkan lagu
void playBirthdaySong() {
for (int thisNote = 0; thisNote < 24; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(BUZZER_PIN, melody[thisNote], noteDuration);
// pause antara nada
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop suara setelah setiap nada
noTone(BUZZER_PIN);
}
}
void setup() {
// Memulai komunikasi dengan OLED
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("OLED tidak ditemukan"));
for(;;);
}
display.clearDisplay();
// Menampilkan gambar ulang tahun (ganti dengan gambar Anda nanti)
display.drawBitmap(0, 0, birthday_image_bits, 128, 64, WHITE);
display.display();
// Menunggu beberapa detik agar gambar tampil
delay(3000);
// Tampilkan pesan selamat ulang tahun
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 10);
display.println(F("Selamat Ulang Tahun!"));
display.setCursor(10, 30);
display.println(F("Semoga Sukses Selalu!"));
display.display();
// Mainkan lagu ulang tahun setelah pesan
delay(2000); // Tunggu sebentar sebelum lagu dimainkan
playBirthdaySong();
}
void loop() {
// Tidak ada aksi berulang
}