Delete clock.ino
This commit is contained in:
57
clock.ino
57
clock.ino
@@ -1,57 +0,0 @@
|
|||||||
#include <SPI.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <TFTv2.h>
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <RTClib.h>
|
|
||||||
|
|
||||||
RTC_DS1307 rtc;
|
|
||||||
|
|
||||||
#define TIME_X 5
|
|
||||||
#define TIME_Y 70
|
|
||||||
#define TIME_SIZE 10
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
TFT_BL_ON;
|
|
||||||
Tft.TFTinit();
|
|
||||||
Wire.begin();
|
|
||||||
rtc.begin();
|
|
||||||
|
|
||||||
// Uncomment to set RTC to compile time (do once, then comment out)
|
|
||||||
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
|
||||||
|
|
||||||
// Clear entire screen once
|
|
||||||
Tft.fillScreen(0, 320, 0, 240, BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
static unsigned long lastUpdate = 0;
|
|
||||||
static char lastTime[16] = "";
|
|
||||||
|
|
||||||
if (millis() - lastUpdate >= 1000) {
|
|
||||||
lastUpdate = millis();
|
|
||||||
|
|
||||||
DateTime now = rtc.now();
|
|
||||||
|
|
||||||
// Convert to 12-hour format
|
|
||||||
int hour12 = now.hour();
|
|
||||||
if (hour12 == 0) {
|
|
||||||
hour12 = 12; // Midnight is 12 AM
|
|
||||||
} else if (hour12 > 12) {
|
|
||||||
hour12 -= 12; // Convert PM hours
|
|
||||||
}
|
|
||||||
|
|
||||||
char timebuf[16];
|
|
||||||
sprintf(timebuf, "%02d:%02d", hour12, now.minute());
|
|
||||||
|
|
||||||
// Update time if changed
|
|
||||||
if (strcmp(timebuf, lastTime) != 0) {
|
|
||||||
// Erase old time by drawing in BLACK
|
|
||||||
Tft.drawString(lastTime, TIME_X, TIME_Y, TIME_SIZE, BLACK, LANDSCAPE);
|
|
||||||
|
|
||||||
// Draw new time in WHITE
|
|
||||||
Tft.drawString(timebuf, TIME_X, TIME_Y, TIME_SIZE, WHITE, LANDSCAPE);
|
|
||||||
|
|
||||||
strcpy(lastTime, timebuf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user