#include <LCD_I2C.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LCD_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(115200);
Serial.println("Raspberry Pi Pico dengan RTC");
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));
} else {Serial.println("RTC started successfully");}
lcd.begin();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("GROUP WA ARDUMEKA!");
}
void loop() {
DateTime now = rtc.now();
//buffer can be defined using following combinations:
//hh - the hour with a leading zero (00 to 23)
//mm - the minute with a leading zero (00 to 59)
//ss - the whole second with a leading zero where applicable (00 to 59)
//YYYY - the year as four digit number
//YY - the year as two digit number (00-99)
//MM - the month as number with a leading zero (01-12)
//MMM - the abbreviated English month name ('Jan' to 'Dec')
//DD - the day as number with a leading zero (01 to 31)
//DDD - the abbreviated English day name ('Mon' to 'Sun')
lcd.setCursor(0, 1);
lcd.print(" RTC DS.1307 + PICO ");
lcd.setCursor(0, 2);
char buf4[] = "DD-MMM-YYYY";
lcd.print(now.toString(buf4));
lcd.setCursor(0, 3);
char buf2[] = "hh:mm:ss";
lcd.print(now.toString(buf2));
}