#include "pitches.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h> // Include the RTC library
LiquidCrystal_I2C lcd(0x27,20,4);
RTC_DS3231 rtc; // Create an RTC object
//setup emot
byte customChar[8] = {
0b00000,
0b01010,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000,
};
// setup hw
int SPEAKER_PIN = 11;
int SPEAKER = SPEAKER_PIN;
#define NUM_OF_NOTES 28
#define PAUSE 0
// end of custom
#define NOTE_C5 523
#define NOTE_D5 587
#define NOTE_A5 880
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_G5 784
#define NOTE_AS5 932
#define NOTE_C6 1047
int NOTE_SEQ[NUM_OF_NOTES] = {
NOTE_C5, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_F5, NOTE_E5, PAUSE,
NOTE_C5, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_G5, NOTE_F5, PAUSE,
NOTE_C5, NOTE_C5, NOTE_C6, NOTE_A5, NOTE_F5, NOTE_E5, NOTE_D5, PAUSE,
NOTE_AS5, NOTE_AS5, NOTE_A5, NOTE_F5, NOTE_G5, NOTE_F5
};
int NOTE_LEN[NUM_OF_NOTES] = {
4, 2, 8, 8, 8, 16, 50,
4, 2, 8, 8, 8, 16, 100,
4, 2, 8, 8, 8, 8, 16, 150,
4, 2, 8, 8, 8, 20
};
int TEMPO = 75;
void playNote(int pitch, int duration) {
tone(SPEAKER, pitch);
delay(duration);
noTone(SPEAKER);
}
void setup() {
Wire.begin(); // Initialize I2C communication
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD backlight
lcd.createChar(0, customChar);
lcd.setCursor(0, 0);
lcd.write((byte)0);
lcd.print("happy birthday");
lcd.setCursor(15, 0);
lcd.write((byte)0);
lcd.setCursor(4, 1);
lcd.write((byte)0);
lcd.print("Sassy");
lcd.setCursor(10, 1);
lcd.write((byte)0);
for (int i = 0; i < NUM_OF_NOTES; i++) {
if (NOTE_SEQ[i] != PAUSE) {
playNote(NOTE_SEQ[i], NOTE_LEN[i] * TEMPO);
delay(TEMPO);
} else {
delay(NOTE_LEN[i]);
}
}
if (!rtc.begin()) {
lcd.setCursor(0, 2);
lcd.print("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
lcd.setCursor(0, 2);
lcd.print("RTC lost power");
// Uncomment the next line to set the RTC to the current date & time
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
delay(1000);
}
void loop() {
DateTime now = rtc.now(); // Dapatkan waktu saat ini
// Tampilkan waktu saat ini pada LCD
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(':');
if (now.minute() < 10) lcd.print('0'); // Tambahkan nol di depan jika diperlukan
lcd.print(now.minute());
lcd.print(':');
if (now.second() < 10) lcd.print('0'); // Tambahkan nol di depan jika diperlukan
lcd.print(now.second());
// Tampilkan tanggal saat ini pada LCD dengan hari di depan
lcd.setCursor(0, 0);
lcd.print("Date: ");
if (now.day() < 10) lcd.print('0'); // Tambahkan nol di depan jika diperlukan
lcd.print(now.day());
lcd.print('/');
if (now.month() < 10) lcd.print('0'); // Tambahkan nol di depan jika diperlukan
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year());
delay(1000); // Perbarui waktu setiap detik
}