#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#define bMN 3 // Tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 3 Digital
#define bUP 4 // Tombol OK sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 5 Digital
#define bDN 2 //tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 4 Digital
#define bEX 5
#define relay 7
int jamON;
int menitON;
int jamOFF;
int menitOFF;
int status;
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char monthsOfTheYear[12][4] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
char dOfTheWeek[7][4] = { "Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"};
char setphase = 0;
char setpos = 0;
DateTime now;
void setup () {
lcd.backlight();
pinMode(bMN, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal
pinMode(bUP, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal
pinMode(bDN, INPUT_PULLUP);
pinMode(bEX, INPUT_PULLUP);
pinMode(relay, OUTPUT); //output
Wire.begin();
//Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
}
void loop () {
if (menu == 0) {
while (menu == 0) (
if (digitalRead(bMN) == LOW)
)
}
if (!setphase) {
now = rtc.now();
// 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(2017, 12, 2, 15, 2, 0));
}
int jam = now.hour ();
int menit = now.minute ();
int tanggal = now.day ();
int bulan = now.month();
int tahun = now.year();
int detik = now.second();
char hari = dOfTheWeek[now.dayOfTheWeek()];
lcd.setCursor(0, 0);
lcd.print(dOfTheWeek[now.dayOfTheWeek()]);
lcd.print(",");
lcd.print(tens(tanggal), DEC);
lcd.print(units(tanggal), DEC);
lcd.print("-");
lcd.print(tens(bulan), DEC);
lcd.print(units(bulan), DEC);
lcd.print("-");
lcd.print(tahun);
lcd.setCursor(0, 1);
lcd.print(tens(jam), DEC);
lcd.print(units(jam), DEC);
lcd.print(":");
lcd.print(tens(menit), DEC);
lcd.print(units(menit), DEC);
lcd.print(":");
lcd.print(tens(detik), DEC);
lcd.print(units(detik), DEC);
}
char tens(int n) {
return (n / 10) % 10;
}
char units(int n) {
return n % 10;
}