#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// LCD pin connections (DO NOT CHANGE – matches circuit)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
#define clk 7
#define RST 3
#define ce 4
#define dc 5
#define din 6
// Time variables
int h = 5; // Hour (starts at 12)
int m = 20; // Minute
int s = 0; // Second
int flag = 0; // AM/PM tracking counter
// Time set button pins
const int hs = 8; // Hour set button
const int ms = 9; // Minute set button
// Button states
int state1;
int state2;
void setup()
{
// Initialize LCD
display.begin();
display.setContrast(50);
display.clearDisplay();
// Button inputs
pinMode(hs, INPUT);
pinMode(ms, INPUT);
}
void loop()
{
// Increase seconds every loop (1 second delay below)
s = s + 1;
// Clear display buffer
display.clearDisplay();
// Display hours and minutes
display.setTextSize(1);
display.setCursor(10, 5);
display.print(h);
display.print(":");
display.print(m);
// Display seconds
display.setTextSize(1);
display.print(":");
display.print(s);
// Display AM / PM
display.setTextSize(1);
display.setCursor(10, 20);
if (flag < 12) display.println("AM");
else display.println("PM");
if (flag == 24) flag = 0;
// Message line
display.setTextSize(1);
display.setCursor(10, 35);
display.print("arvind");
// Push data to LCD
display.display();
// 1 second delay
delay(1000);
// Seconds rollover
if (s == 60)
{
s = 0;
m = m + 1;
}
// Minutes rollover
if (m == 60)
{
m = 0;
h = h + 1;
flag = flag + 1;
}
// Hour rollover (12-hour format)
if (h == 13)
{
h = 1;
}
// ----------- Time Setting Section ----------- //
// Hour set button
state1 = digitalRead(hs);
if (state1 == HIGH)
{
h = h + 1;
flag = flag + 1;
if (h == 13) h = 1;
if (flag == 24) flag = 0;
delay(300); // simple debounce
}
// Minute set button
state2 = digitalRead(ms);
if (state2 == HIGH)
{
s = 0;
m = m + 1;
if (m == 60) m = 0;
delay(300); // simple debounce
}
}
Loading
nokia-5110
nokia-5110
https://wokwi.com/projects/466170235301409793
for code and details