Wed. Jul 29th, 2026
#include <Wire.h>
#include <TFT_eSPI.h>
#include "DS1307.h" 

TFT_eSPI tft = TFT_eSPI();
DS1307 clock; 

void setup() {
    tft.begin();
    tft.setRotation(3); 
    tft.fillScreen(TFT_BLACK);
    
    clock.begin();
    
    // FORCE START: This kicks the hardware crystal into action
    clock.startClock(); 

    // Hardcode current time (matching tonight's actual time!)
    clock.fillByYMD(2026, 6, 15); 
    clock.fillByHMS(22, 20, 0); 
    clock.setTime(); 
}

void loop() {
    clock.getTime(); 

    // If the chip returns impossible data, flash a warning
    if (clock.minute > 59 || clock.second > 59) {
        tft.setTextSize(3);
        tft.setTextColor(TFT_RED, TFT_BLACK);
        tft.drawString("Check Wire / Port", 20, 100);
    } else {
        char timeString[16]; 
        sprintf(timeString, "%02d:%02d:%02d", clock.hour, clock.minute, clock.second);

        tft.setTextSize(5);
        tft.setTextColor(TFT_GREEN, TFT_BLACK); 
        tft.drawString(timeString, 45, 100);
    }

    delay(1000); 
}

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *