added blinking dots

This commit is contained in:
2026-01-18 18:49:52 -05:00
parent 8f8dc2e0fa
commit 849d6a46bf

View File

@@ -1,175 +1,187 @@
#include <RTClib.h> #include <RTClib.h>
#include <SPI.h> #include <SPI.h>
#include "LCD_Driver.h" #include "LCD_Driver.h"
#include "GUI_Paint.h" #include "GUI_Paint.h"
#include "image.h" #include "image.h"
#include <Wire.h> #include <Wire.h>
RTC_DS1307 rtc; RTC_DS1307 rtc;
int DIGIT_SIZE = 40; int DIGIT_SIZE = 40;
// Month + weekday names // Month + weekday names
const char* MONTH_NAMES[] = { const char* MONTH_NAMES[] = {
"January", "February", "March", "April", "May", "June", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" "July", "August", "September", "October", "November", "December"
}; };
const char* WEEKDAY_NAMES[] = { const char* WEEKDAY_NAMES[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" "Thursday", "Friday", "Saturday"
}; };
// --------------------------- // ---------------------------
// DRAW HELPERS // DRAW HELPERS
// --------------------------- // ---------------------------
void drawSegment(int x, int y, int w, int h, uint16_t color) { void drawSegment(int x, int y, int w, int h, uint16_t color) {
Paint_DrawRectangle(x, y, x + w, y + h, color, Paint_DrawRectangle(x, y, x + w, y + h, color,
DOT_PIXEL_1X1, DRAW_FILL_FULL); DOT_PIXEL_1X1, DRAW_FILL_FULL);
} }
void drawDigit(int x, int y, int size, int digit, uint16_t color) { void drawDigit(int x, int y, int size, int digit, uint16_t color) {
int thick = size / 5; int thick = size / 5;
int longSeg = size; int longSeg = size;
int wideSeg = size; int wideSeg = size;
bool A=false, B=false, C=false, D=false, E=false, F=false, G=false; bool A=false, B=false, C=false, D=false, E=false, F=false, G=false;
switch (digit) { switch (digit) {
case 0: A=B=C=D=E=F=true; break; case 0: A=B=C=D=E=F=true; break;
case 1: B=C=true; break; case 1: B=C=true; break;
case 2: A=B=G=E=D=true; break; case 2: A=B=G=E=D=true; break;
case 3: A=B=G=C=D=true; break; case 3: A=B=G=C=D=true; break;
case 4: F=G=B=C=true; break; case 4: F=G=B=C=true; break;
case 5: A=F=G=C=D=true; break; case 5: A=F=G=C=D=true; break;
case 6: A=F=G=E=C=D=true; break; case 6: A=F=G=E=C=D=true; break;
case 7: A=B=C=true; break; case 7: A=B=C=true; break;
case 8: A=B=C=D=E=F=G=true; break; case 8: A=B=C=D=E=F=G=true; break;
case 9: A=B=C=D=F=G=true; break; case 9: A=B=C=D=F=G=true; break;
} }
if (A) drawSegment(x + thick, y, wideSeg, thick, color); if (A) drawSegment(x + thick, y, wideSeg, thick, color);
if (B) drawSegment(x + wideSeg + thick, y + thick, thick, longSeg, color); if (B) drawSegment(x + wideSeg + thick, y + thick, thick, longSeg, color);
if (C) drawSegment(x + wideSeg + thick, y + thick + longSeg + thick, thick, longSeg, color); if (C) drawSegment(x + wideSeg + thick, y + thick + longSeg + thick, thick, longSeg, color);
if (D) drawSegment(x + thick, y + 2*longSeg + 2*thick, wideSeg, thick, color); if (D) drawSegment(x + thick, y + 2*longSeg + 2*thick, wideSeg, thick, color);
if (E) drawSegment(x, y + thick + longSeg + thick, thick, longSeg, color); if (E) drawSegment(x, y + thick + longSeg + thick, thick, longSeg, color);
if (F) drawSegment(x, y + thick, thick, longSeg, color); if (F) drawSegment(x, y + thick, thick, longSeg, color);
if (G) drawSegment(x + thick, y + longSeg + thick, wideSeg, thick, color); if (G) drawSegment(x + thick, y + longSeg + thick, wideSeg, thick, color);
} }
void drawColon(int x, int y, int size, uint16_t color) { void drawColon(int x, int y, int size, uint16_t color) {
int dot = size / 5; int dot = size / 5;
drawSegment(x, y + size/2 - 10, dot, dot, color); drawSegment(x, y + size/2 - 10, dot, dot, color);
drawSegment(x, y + size + 10, dot, dot, color); drawSegment(x, y + size + 10, dot, dot, color);
} }
// --------------------------- // ---------------------------
// SETUP // SETUP
// --------------------------- // ---------------------------
void setup() { void setup() {
Wire.begin(); Wire.begin();
rtc.begin(); rtc.begin();
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // run once if needed // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // run once if needed
Config_Init(); Config_Init();
LCD_Init(); LCD_Init();
LCD_Clear(BLACK); LCD_Clear(BLACK);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 90, BLACK); Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 90, BLACK);
Paint_Clear(BLACK); Paint_Clear(BLACK);
Paint_DrawString_EN(30, 110, "Starting Up...", &Font24, BLACK, GREEN); Paint_DrawString_EN(30, 110, "Starting Up...", &Font24, BLACK, GREEN);
delay(1000); delay(1000);
Paint_Clear(BLACK); Paint_Clear(BLACK);
} }
// --------------------------- // ---------------------------
// LOOP // LOOP
// --------------------------- // ---------------------------
void loop() { static bool colonOn = true;
static unsigned long lastUpdate = 0;
static char lastTime[16] = ""; void loop() {
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 1000) { static char lastTime[16] = "";
lastUpdate = millis();
if (millis() - lastUpdate >= 1000) {
DateTime now = rtc.now(); lastUpdate = millis();
// Convert to 12-hour format DateTime now = rtc.now();
int hour12 = now.hour(); colonOn = !colonOn;
if (hour12 == 0) hour12 = 12;
else if (hour12 > 12) hour12 -= 12; // Convert to 12-hour format
int hour12 = now.hour();
char timebuf[16]; if (hour12 == 0) hour12 = 12;
sprintf(timebuf, "%02d:%02d", hour12, now.minute()); else if (hour12 > 12) hour12 -= 12;
// Build weekday + date strings char timebuf[16];
char weekdaybuf[16]; sprintf(timebuf, "%02d:%02d", hour12, now.minute());
char datebuf[32];
// Build weekday + date strings
sprintf(weekdaybuf, "%s", WEEKDAY_NAMES[now.dayOfTheWeek()]); char weekdaybuf[16];
sprintf(datebuf, "%s %d, %d", char datebuf[32];
MONTH_NAMES[now.month() - 1],
now.day(), sprintf(weekdaybuf, "%s", WEEKDAY_NAMES[now.dayOfTheWeek()]);
now.year()); sprintf(datebuf, "%s %d, %d",
MONTH_NAMES[now.month() - 1],
// Draw weekday + date (always update) now.day(),
Paint_DrawString_EN(15, 160, weekdaybuf, &Font24, BLACK, WHITE); now.year());
Paint_DrawString_EN(15, 200, datebuf, &Font24, BLACK, WHITE);
// Draw weekday + date (always update)
// Only update digits that changed Paint_DrawString_EN(15, 160, weekdaybuf, &Font24, BLACK, WHITE);
if (strcmp(timebuf, lastTime) != 0) { Paint_DrawString_EN(15, 200, datebuf, &Font24, BLACK, WHITE);
int size = DIGIT_SIZE; int colonX = 10 + 2*(DIGIT_SIZE + 35);
int colonTopY = 50;
// Extract digits int colonBottomY = 100;
int h1 = hour12 / 10; int colonW = 10;
int h2 = hour12 % 10; int colonH = 10;
int m1 = now.minute() / 10;
int m2 = now.minute() % 10; uint16_t colonColor = colonOn ? WHITE : BLACK;
// HOUR tens // Top dot
if (lastTime[0] != timebuf[0]) { Paint_DrawRectangle(colonX, colonTopY,
if (h1 == 0) colonX + colonW, colonTopY + colonH,
{ colonColor, DOT_PIXEL_1X1, DRAW_FILL_FULL);
drawDigit(10, 20, size, h1, BLACK);
} // Bottom dot
else Paint_DrawRectangle(colonX, colonBottomY,
{ colonX + colonW, colonBottomY + colonH,
drawDigit(10, 20, size, lastTime[0] - '0', BLACK); colonColor, DOT_PIXEL_1X1, DRAW_FILL_FULL);
drawDigit(10, 20, size, h1, WHITE);
} // Only update digits that changed
} if (strcmp(timebuf, lastTime) != 0) {
// HOUR ones int size = DIGIT_SIZE;
if (lastTime[1] != timebuf[1]) {
drawDigit(10 + size + 30, 20, size, lastTime[1] - '0', BLACK); // Extract digits
drawDigit(10 + size + 30, 20, size, h2, WHITE); int h1 = hour12 / 10;
} int h2 = hour12 % 10;
int m1 = now.minute() / 10;
// COLON (always drawn) int m2 = now.minute() % 10;
Paint_DrawRectangle(10 + 2*(size + 35), 50,
10 + 2*(size + 35) + 10, 60, // HOUR tens
WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL); if (lastTime[0] != timebuf[0]) {
if (h1 == 0)
Paint_DrawRectangle(10 + 2*(size + 35), 100, {
10 + 2*(size + 35) + 10, 110, drawDigit(10, 20, size, h1, BLACK);
WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL); }
else
// MIN tens {
if (lastTime[3] != timebuf[3]) { drawDigit(10, 20, size, lastTime[0] - '0', BLACK);
drawDigit(10 + 2*(size + 30) + 30, 20, size, lastTime[3] - '0', BLACK); drawDigit(10, 20, size, h1, WHITE);
drawDigit(10 + 2*(size + 30) + 30, 20, size, m1, WHITE); }
} }
// MIN ones // HOUR ones
if (lastTime[4] != timebuf[4]) { if (lastTime[1] != timebuf[1]) {
drawDigit(10 + 3*(size + 30) + 30, 20, size, lastTime[4] - '0', BLACK); drawDigit(10 + size + 30, 20, size, lastTime[1] - '0', BLACK);
drawDigit(10 + 3*(size + 30) + 30, 20, size, m2, WHITE); drawDigit(10 + size + 30, 20, size, h2, WHITE);
} }
strcpy(lastTime, timebuf); // MIN tens
} if (lastTime[3] != timebuf[3]) {
} drawDigit(10 + 2*(size + 30) + 30, 20, size, lastTime[3] - '0', BLACK);
} drawDigit(10 + 2*(size + 30) + 30, 20, size, m1, WHITE);
}
// MIN ones
if (lastTime[4] != timebuf[4]) {
drawDigit(10 + 3*(size + 30) + 30, 20, size, lastTime[4] - '0', BLACK);
drawDigit(10 + 3*(size + 30) + 30, 20, size, m2, WHITE);
}
strcpy(lastTime, timebuf);
}
}
}