0% found this document useful (0 votes)
173 views3 pages

Digital Clock Arduino Uno Code With I2c 1602 LCD

This document contains a code for a digital clock implemented using an Arduino and an LCD display. It initializes the LCD, displays the current time, and allows for minute and hour adjustments through button inputs. The clock updates every second and toggles between AM and PM based on the time value.

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)
173 views3 pages

Digital Clock Arduino Uno Code With I2c 1602 LCD

This document contains a code for a digital clock implemented using an Arduino and an LCD display. It initializes the LCD, displays the current time, and allows for minute and hour adjustments through button inputs. The clock updates every second and toggles between AM and PM based on the time value.

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
You are on page 1/ 3

// digital clock by Haseeb Electronics (YouTube Channel)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
int hrsT =0;
int hrsU =8;
int minutesT =3;
int minutesU=6;
int TIME=20;
int secsT =5;
int secsU=5;
int specifiedDelay =1000;
int minSettingBtn = 2;
int minBtnState = HIGH; //it is pulled up with 10K resistor
int hrsSettingBtn = 3;
int hrsBtnState = HIGH; //it is pulled up with 10K resistor

void setup() {
// put your setup code here, to run once:
lcd.init(); //it is to initilize the LCD
lcd.backlight(); //it will turn on the LCD backlight
lcd.setCursor(0,0);
lcd.print("HASEEB");
lcd.setCursor(0,1);
lcd.print("ELECTRONICS");
delay(500);
lcd.clear();
pinMode(minSettingBtn, INPUT);
pinMode(hrsSettingBtn, INPUT);

void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
lcd.print("IT IS:");
lcd.print(hrsT);
lcd.print(hrsU);
lcd.print(":");
lcd.print(minutesT);
lcd.print(minutesU);
lcd.print(":");
lcd.print(secsT);
lcd.print(secsU);

//----------------seconds units
-------------------------------------------------------------
secsU = secsU + 01;
delay(specifiedDelay);

//------------------------ secs tens


-----------------------------------------------
if(secsU==10){
secsU=0;
secsT=secsT+1;
}
// ------------------------------- minutes units
------------------------------------------
if (secsT==6){
secsT = 0;
minutesU = minutesU + 1;
}
//----------------------------------minutes inc
block---------------------------------------
minBtnState = digitalRead(minSettingBtn);
if(minBtnState == LOW){
delay(100);
secsU = 0;
secsT = 0;
minutesU = minutesU +1;
}

//----------------------------------minutes tens
--------------------------------------------
if(minutesU==10){
minutesU=0;
minutesT= minutesT+1;
}

// ------------------------------- hrs units


------------------------------------------
if (minutesT==6){
minutesT = 0;
hrsU = hrsU + 1;
TIME = TIME+1;
}
//----------------------------------hrs inc
block---------------------------------------
hrsBtnState = digitalRead(hrsSettingBtn);
if(hrsBtnState == LOW){
delay(100);
hrsU = hrsU + 1;
TIME = TIME+1;
}

// ---------------------------hrs tens---------------------------------------------
if(hrsU==10){
hrsU=0;
hrsT=hrsT+1;
}
//----------------------------------
TIME--------------------------------------------
if (TIME<12){
lcd.setCursor(14,0);
lcd.print("AM");
}
else{
lcd.setCursor(14,0);
lcd.print("PM");
}

if (TIME== 13){
hrsU = 1;
hrsT=0;
}
if(TIME==24){
lcd.setCursor(14,0);
lcd.print("AM");
}
if(TIME==25){
hrsT=0;
hrsU=1;
TIME=1;
}
}

You might also like