// LIBARARY ARDUINO NANO RTC AND LCD I2C ADAFRUIT :
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
// SERIAL RTC AND LCD I2C :
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
//INTRODUCING THE DAY IN RTC :
char daysOfTheWeek[7][12] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"};
void setup() {
// SET RTC AND LCD I2C :
lcd.init ();
lcd.backlight ();
while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(57600);
if (! rtc.begin()) {
lcd.println("Couldn't find RTC"); // ! artinya tidak sama dengan
while (1);
}
if (! rtc.isrunning()) {
lcd.println("RTC is NOT running!");
// Kalau mau program pertama harus disetting dahulu dengan menghapus commandnya dahulu
//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
// November 20, 2023 at 3am you would call:
// rtc.adjust(DateTime(2023, 11, 20, 11, 10, 0));
} }
void loop() {
// DISPLAY IN LCD I2C :
DateTime now = rtc.now();
lcd.setCursor (3,0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.setCursor ( 1,1 );
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print (" ,");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println();
delay ( 1000 );
}
// NAMA : MUHAMMAD RAFI BAIHAQI
// KELAS : 12 LISTRIK 1
// ABSEN : 26