#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
const int buzzerPin = 8;
// Jam-jam tertentu untuk berbunyi (format: HH, MM)
const int alarmTimes[][2] = {
{9, 39}, // Jam 07:00
{12, 0}, // Jam 12:00
{18, 0} // Jam 18:00
};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
// Inisialisasi RTC
if (!rtc.begin()) {
Serial.println("RTC tidak ditemukan!");
while (1);
}
// Jika RTC tidak pernah disetel, setel waktu di sini
if (!rtc.isrunning()) {
// Atur waktu di sini, misalnya:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
// Cek setiap jam yang ditentukan
for (int i = 0; i < sizeof(alarmTimes) / sizeof(alarmTimes[0]); i++) {
if (now.hour() == alarmTimes[i][0] && now.minute() == alarmTimes[i][1]) {
tone(buzzerPin, 1000); // Bunyi buzzer
delay(1000); // Durasi bunyi
noTone(buzzerPin); // Matikan buzzer
delay(60000); // Tunggu 1 menit untuk menghindari berbunyi berkali-kali
}
}
delay(1000); //
}