#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "RTClib.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
RTC_DS1307 rtc;
String Hour;
String Minute;
String Second;
String RealHour;
String RealMinute;
String RealSecond;
int8_t goodNumbers[16] {2, 4, 8, 11, 14, 18, 19, 20, 21, 22, 24, 36, 42, 44, 49, 56};
void setup() {
// put your setup code here, to run once:
tft.begin();
rtc.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(6);
tft.setCursor(167, 90);
tft.println(":");
tft.setCursor(67, 90);
tft.println(":");
tft.setCursor(0, 10);
tft.setTextColor(ILI9341_PINK);
tft.println("<3 <3 <3");
DateTime now = rtc.now();
if (int8_t(now.second()) < 10) {
Second = "0" + String(now.second());
}
else {
Second = String(now.second());
}
tft.setCursor(200, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Second);
if (int8_t(now.minute()) < 10) {
Minute = "0" + String(now.minute());
}
else {
Minute = String(now.minute());
}
tft.setCursor(100, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Minute);
if (int8_t(now.hour()) < 10) {
Hour = "0" + String(now.hour());
}
else {
Hour = String(now.hour());
}
tft.setCursor(0, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Hour);
}
void loop() {
DateTime now = rtc.now();
if (RealSecond != String(now.second()))
{
for (int i = 0; i < 16; i++)
{
if (now.second() == goodNumbers[i])
{
//Reset the seconds
tft.setCursor(200, 90);
tft.setTextColor(ILI9341_BLACK);
tft.println(Second);
//Leading Zeros
if (int8_t(now.second()) < 10) {
Second = "0" + String(now.second());
}
else {
Second = String(now.second());
}
tft.setCursor(200, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Second);
if (RealMinute != String(now.minute()))
{
//Reset the seconds
tft.setCursor(100, 90);
tft.setTextColor(ILI9341_BLACK);
tft.println(Minute);
//Leading Zeros
if (int8_t(now.minute()) < 10) {
Minute = "0" + String(now.minute());
}
else {
Minute = String(now.minute());
}
tft.setCursor(100, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Minute);
if (RealHour != String(now.hour()))
{
//Reset the seconds
tft.setCursor(0, 90);
tft.setTextColor(ILI9341_BLACK);
tft.println(Hour);
//Leading Zeros
if (int8_t(now.hour()) < 10) {
Hour = "0" + String(now.hour());
}
else {
Hour = String(now.hour());
}
tft.setCursor(0, 90);
tft.setTextColor(ILI9341_GREEN);
tft.println(Hour);
}
}
}
}
}
RealHour = now.hour();
RealMinute = now.minute();
RealSecond = now.second();
delay(100);
}