#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
RTC_DS1307 rtc;
void drawTopIcons() {
// Battery icon (top-right)
display.drawRect(114, 0, 12, 6, WHITE); // battery body
display.drawRect(126, 2, 2, 2, WHITE); // cap
display.fillRect(116, 2, 8, 2, WHITE); // battery fill
// Network bars (top-left)
display.drawLine(0, 6, 0, 6, WHITE);
display.drawLine(3, 4, 3, 6, WHITE);
display.drawLine(6, 2, 6, 6, WHITE);
display.drawLine(9, 0, 9, 6, WHITE);
}
void drawBottomUnlockIcon(int x, int y) {
// Small lock icon
display.drawRect(x, y + 3, 10, 6, WHITE); // lock body
display.drawCircle(x + 5, y, 3, WHITE); // shackle
display.drawLine(x + 2, y, x + 8, y, BLACK); // open part
}
void setup() {
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
rtc.begin();
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set to compile time
}
display.setTextColor(WHITE);
}
void loop() {
DateTime now = rtc.now();
display.clearDisplay();
// Draw battery & network icons
drawTopIcons();
// Draw big time (HH:MM) in center
display.setTextSize(3);
display.setCursor(10, 20); // Y=20 leaves room above and below
// Hour
if (now.hour() < 10) display.print('0');
display.print(now.hour());
// Blinking colon
if (now.second() % 2 == 0) {
display.print(':');
} else {
display.print(' ');
}
// Minute
if (now.minute() < 10) display.print('0');
display.print(now.minute());
// Draw date and day in small font at bottom
display.setTextSize(1);
display.setCursor(0, 54);
if (now.day() < 10) display.print('0');
display.print(now.day());
display.print('-');
if (now.month() < 10) display.print('0');
display.print(now.month());
display.print('-');
display.print(now.year());
// Day of week
display.setCursor(70, 54);
const char* days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
display.print(days[now.dayOfTheWeek()]);
// Unlock icon (bottom right)
drawBottomUnlockIcon(110, 52);
display.display();
delay(1000);
}