#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include "RTClib.h"
RTC_DS1307 rtc;
char dataHari[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
String hari;
int tanggal, bulan, tahun, jam, menit, detik;
const int bzPIN = 13;
void setup() {
Serial.begin(9600);
Wire.begin();
if (! rtc.begin())
{
Serial.println("RTC OFF");
Serial.flush();
abort();
}
lcd.init();
lcd.backlight();
pinMode(bzPIN, OUTPUT);
}
void loop() {
DateTime now = rtc.now();
hari = dataHari[now.dayOfTheWeek()];
tanggal = now.day();
bulan = now.month();
tahun = now.year();
jam = now.hour();
menit = now.minute();
detik = now.second();
lcd.setCursor(2,0);
lcd.print(String() +hari+"," +tanggal+"-"+bulan+"-"+tahun);
lcd.setCursor(4,1);
lcd.print(String() +jam+":" +menit+":"+detik);
noTone(bzPIN);
delay(500);
Serial.print(dataHari[now.dayOfTheWeek()]);
Serial.print(',');
Serial.print(now.day(), DEC);
Serial.print('-');
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.print(now.year(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(500);
//setting alarm
if (now.hour() == 14 && now.minute() == 31){
buzzer_on();
}
}
void buzzer_on() {
tone(bzPIN, 1000); // Send 1KHz sound signal...
delay(500); // ...for 1 sec
noTone(bzPIN); // Stop sound...
//digitalWrite(buzzer, HIGH); //untuk buzzer active low
delay(500); // ...for 1sec
}