#include <Wire.h>
#include "RTClib.h"
#define SPEAKER_PIN 7
int song[] = {500, 1000, 1500, 2000, 1500, 1000, 500};
int durasi[] = {80, 180, 280, 380, 500, 1000, 1500};
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
pinMode("buzzer", OUTPUT);
while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void alarm(int tanggal_alarm, int jam_alarm, int menit_alarm) {
DateTime now = rtc.now();
long elapsed_time = 0;
int day = now.day();
int jam = now.hour();
int menit = now.minute();
if (tanggal_alarm == day) {
if (jam_alarm == jam) {
if (menit_alarm == menit) {
for (int note = 0; note < 7; note ++) {
tone("pinbuzz", song[note], durasi[note]);
delay(durasi[note]);
Serial.println("ALARM BUNYI!!!");
}
}
}
delay(1000);
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
delay(1000);
//set ALARM (tgl,jam,menit)
alarm(6, 48, 00);
}