0% found this document useful (0 votes)
14 views2 pages

My Code!

This document contains an Arduino sketch for a digital clock using a LiquidCrystal display. It allows users to change the time using buttons for hours and minutes, with specific logic for incrementing and decrementing values. The clock updates every second and displays the current time in a 12-hour format.

Uploaded by

Rajendra Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

My Code!

This document contains an Arduino sketch for a digital clock using a LiquidCrystal display. It allows users to change the time using buttons for hours and minutes, with specific logic for incrementing and decrementing values. The clock updates every second and displays the current time in a 12-hour format.

Uploaded by

Rajendra Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <LiquidCrystal.

h>
//to change time, hold chanage time button for 1 second, then use hour chnage and
minute change buttons.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


int hour = 12;
int minutes = 0;
int seconds = 0;
int decBtn = 10;
int hrUp = 9;
int hrDwn = 8;
int minUp = 7;
int minDwn = 6;
int hrUpDec = 0;
int hrDwnDec = 0;
int minUpDec = 0;
int minDwnDec = 0;

void setup() {
[Link](16, 2);
pinMode(decBtn, INPUT);
pinMode(hrUp, INPUT);
pinMode(hrDwn, INPUT);
pinMode(minUp, INPUT);
pinMode(minDwn, INPUT);
}

void loop() {
if (digitalRead(decBtn) == HIGH) {
if (digitalRead(hrUp) == HIGH && hrUpDec == 0) {
hrUpDec = 1;
hour = hour + 1;
} else if (digitalRead(hrUp) == LOW) {
hrUpDec = 0;
}
if (digitalRead(hrDwn) == HIGH && hrDwnDec == 0) {
hrDwnDec = 1;
hour = hour - 1;
} else if (digitalRead(hrDwn) == LOW) {
hrDwnDec = 0;
}
if (digitalRead(minUp) == HIGH && minUpDec == 0) {
minUpDec = 1;
minutes = minutes + 1;
} else if (digitalRead(minUp) == LOW) {
minUpDec = 0;
}
if (digitalRead(minDwn) == HIGH && minDwnDec == 0) {
minDwnDec = 1;
minutes = minutes - 1;
} else if (digitalRead(minDwn) == LOW) {
minDwnDec = 0;
}
seconds = 0;
[Link]();
if (minutes == 60) {
minutes = 0;
hour = hour + 1;
}
if (minutes < 0) {
minutes = 59;
}
if (hour == 13) {
hour = 1;
}
if (hour < 1) {
hour = 12;
}
[Link](hour);
[Link](":");
if (minutes < 10) {
[Link](0);
}
[Link](minutes);
delay(20);
} else if (digitalRead(decBtn) == LOW) {
[Link]();
if (seconds == 60) {
seconds = 0;
minutes = minutes + 1;
}
if (minutes == 60) {
minutes = 0;
hour = hour + 1;
}
if (minutes < 0) {
minutes = 59;
}
if (hour == 13) {
hour = 1;
}
if (hour < 1) {
hour = 12;
}
[Link](hour);
[Link](":");
if (minutes < 10) {
[Link](0);
}
[Link](minutes);
delay(1000);
[Link]();
seconds = seconds + 1;
}
}

You might also like