#include <PCD8544.h>
#include <Wire.h>
#include <RTClib.h>
// A custom glyph (a smiley)...
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
static PCD8544 lcd;
RTC_DS3231 rtc;
void setup() {
// Initialize LCD and RTC
lcd.begin(84, 48);
lcd.createChar(0, glyph);
if (!rtc.begin()) {
lcd.setCursor(0, 0);
lcd.print("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
lcd.setCursor(0, 0);
lcd.print("RTC lost power");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the time to compile time
}
}
void loop() {
DateTime now = rtc.now();
// Line 1: Display time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tm:");
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
delay(1000);
// Line 2: Display date
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Dt:");
lcd.setCursor(0, 3);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
delay(1000);
}