#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
RTC_DS1307 rtc;
void setup() {
Serial.begin(115200);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
Wire.begin();
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime(2024, 1, 1, 0, 0, 0));
}
}
void loop() {
DateTime now = rtc.now();
tft.fillRect(0, 80, 240, 40, ILI9341_BLACK);
tft.setCursor(40, 80);
tft.setTextSize(2);
tft.print("Time: ");
tft.print(now.hour(), DEC);
tft.print(":");
tft.print(now.minute(), DEC);
tft.print(":");
tft.print(now.second(), DEC);
Serial.println("Time: ");
Serial.println(now.hour(), DEC);
Serial.println(now.minute(), DEC);
Serial.println(now.second(), DEC);
delay(1000);
}