#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
int hours=0,minutes=0,seconds=0;
String am_pm=" AM";
void setup() {
lcd.begin(16,2);
}
void loop() {
lcd.setCursor(5,0);
lcd.print("CLOCK");
lcd.setCursor(3,1);
if(seconds==59 && minutes!=59){
minutes++;
seconds=0;
}
if(minutes==59 && seconds==59 && hours!=23){
hours++;
minutes=0;
seconds=0;
}
if(hours==12 && minutes==0 && seconds==0){
am_pm=" PM";
}
if(hours==23 && minutes==59 && seconds==59){
hours=0;
minutes=0;
seconds=0;
am_pm=" AM";
}
String s1=(String)hours;
String s2=(String)minutes;
String s3=(String)seconds;
String s="";
if(s1.length()==1){
s+="0"+s1;
}
else if(s1.length()==2){
s+=s1;
}
s+=":";
if(s2.length()==1){
s+="0"+s2;
}
else if(s2.length()==2){
s+=s2;
}
s+=":";
if(s3.length()==1){
s+="0"+s3;
}
else if(s3.length()==2){
s+=s3;
}
lcd.print(s+am_pm);
seconds++;
delay(1000);
}