#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// LCD pin connections (matches your circuit)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
// Time variables (start time)
int h = 12; // Hour
int m = 15; // Minute
int s = 0; // Second
// Center of clock face
const int cx = 42; // X center
const int cy = 24; // Y center
const int radius = 20;
void setup() {
display.begin();
display.setContrast(50);
display.clearDisplay();
display.display();
}
void loop() {
// Clear screen
display.clearDisplay();
// Draw clock circle
display.drawCircle(cx, cy, radius, BLACK);
// Draw tick marks (12 hours)
for (int i = 0; i < 12; i++) {
float angle = i * 30 * PI / 180; // 30° per hour
int x1 = cx + cos(angle) * (radius - 2);
int y1 = cy + sin(angle) * (radius - 2);
int x2 = cx + cos(angle) * radius;
int y2 = cy + sin(angle) * radius;
display.drawLine(x1, y1, x2, y2, BLACK);
}
// Calculate hand angles
float secAngle = s * 6 * PI / 180; // 6° per second
float minAngle = (m + s / 60.0) * 6 * PI / 180; // 6° per minute
float hourAngle = (h % 12 + m / 60.0) * 30 * PI / 180; // 30° per hour
// Second hand
int sx = cx + cos(secAngle) * (radius - 2);
int sy = cy + sin(secAngle) * (radius - 2);
display.drawLine(cx, cy, sx, sy, BLACK);
// Minute hand
int mx = cx + cos(minAngle) * (radius - 5);
int my = cy + sin(minAngle) * (radius - 5);
display.drawLine(cx, cy, mx, my, BLACK);
// Hour hand
int hx = cx + cos(hourAngle) * (radius - 10);
int hy = cy + sin(hourAngle) * (radius - 10);
display.drawLine(cx, cy, hx, hy, BLACK);
// Signature
display.setCursor(0, 40);
display.setTextSize(1);
display.print("arvind");
// Push to LCD
display.display();
// Delay 1 second
delay(1000);
// Update time
s++;
if (s == 60) {
s = 0;
m++;
}
if (m == 60) {
m = 0;
h++;
}
if (h == 13) {
h = 1;
}
}
https://wokwi.com/projects/466170235301409793
for code and details