#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#define TFT_GREY 0x5AEB
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
uint32_t targetTime = 0; // for next 1 second timeout
static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time
byte omm = 99, oss = 99;
byte xcolon = 0, xsecs = 0;
unsigned int colour = 0;
void setup(void) {
Serial.begin(115200); // Enable serial debugging
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_WHITE);
tft.setTextSize(1);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
// Draw static elements
tft.drawCentreString("PM", 30, 30, 2); // "PM" at the top-left corner
tft.drawCentreString("IXLens", 160, 30, 2); // "IXLens" at the top-center
tft.drawCentreString("🔔", 290, 30, 2); // Bell icon at the top-right corner
tft.drawCentreString("815°F", 40, 220, 2); // Bottom-left text
tft.drawCentreString("27 Dec 21", 160, 220, 2); // Bottom-center date
tft.drawCentreString("CODICOL AL", 280, 220, 2); // Bottom-right text
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis() + 1000;
ss++;
if (ss == 60) {
ss = 0;
omm = mm;
mm++;
if (mm > 59) {
mm = 0;
hh++;
if (hh > 23) {
hh = 0;
}
}
}
int xpos = 70;
int ypos = 85;
int ysecs = ypos + 17;
if (omm != mm) {
omm = mm;
tft.fillRect(0, ypos, tft.width(), 48, TFT_WHITE);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
if (hh < 10) xpos += tft.drawChar('0', xpos, ypos, 6);
xpos += tft.drawNumber(hh, xpos, ypos, 6);
xcolon = xpos;
xpos += tft.drawChar(':', xpos, ypos, 6);
if (mm < 10) xpos += tft.drawChar('0', xpos, ypos, 6);
xpos += tft.drawNumber(mm, xpos, ypos, 6);
xsecs = xpos;
tft.drawCentreString("Wednesday", (tft.width() / 2)-10, ypos + 48, 4);
}
if (oss != ss) {
oss = ss;
xpos = xsecs;
if (ss % 2) {
tft.setTextColor(TFT_GREY, TFT_WHITE);
tft.drawChar(':', xcolon, ypos, 6);
xpos += tft.drawChar(' ', xsecs, ysecs, 4);
tft.setTextColor(TFT_BLACK, TFT_WHITE);
} else {
tft.drawChar(':', xcolon, ypos, 6);
xpos += tft.drawChar(' ', xsecs, ysecs, 4);
}
if (ss < 10) xpos += tft.drawChar('0', xpos, ysecs, 4);
tft.drawNumber(ss, xpos, ysecs, 4);
}
}
}
// Function to extract numbers from compile time string
static uint8_t conv2d(const char* p) {
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}