# Displaying time on LCD shield screen using Arduino

Hello

I am trying to use my Arduino to display the time since the Arduino was switched on in hours, minutes and seconds using the millis function on an lcd shield.

On the second line of the lcd shield it will also say good morning, afternoon or evening depending on how long the Arduino is switched on for (The time of day relies on the assumption that the Arduino will be switched on at 12am, however as this is just for a prototype this is ok)

Currently the LCD screen is blank

I am a complete beginner so any tips/ advice as to why this code is not working is helpful!

Thank you

//Digital arduino lcd clock using millis funtion

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

unsigned long s; //use for the function to figure out the times
unsigned long m;
unsigned long h;

int flag; // AM OR PM
int TIME;

const int hs=8; //input pin numbers
const int ms=9;

void setup() {
// put your setup code here, to run once:

lcd.begin(16,2);
pinMode(hs,INPUT);
pinMode(ms,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
s= millis()/1000; //use the millis funtion to work out the time since the arduino was switched on
m= millis()/60000;
h= millis()/3600000;
flag= 1;

if (m<0){ //Making sure that it does not show decimal places
m=0;
}
if (h<0){ //Making sure that it does not show decimal places
h=0;
}
if(h==13){
h=1; //How do i then make it count then so 14=2, 15=3 etc without extra if functions?
}
if (h=h+1){ //Will this work
flag=flag+1;
}
//Printing time
lcd.setCursor(0,0);
lcd.print("TIME:");
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);

//Considering if it is AM or PM and
if(flag<12){lcd.print("AM");
lcd.setCursor(0,1);
lcd.print ("Good Morning!");
}
if(flag==12){lcd.print("PM");
}
if(12<flag<16){lcd.print("PM");
lcd.setCursor(0,1);
lcd.print ("Good Afternoon!");
}
if(flag>16) {lcd.print("PM");
lcd.setCursor(0,1);
lcd.print ("Good Evening!");
}
if(flag==24)flag=0; //goes back to AM

if(flag==25){
flag=1;
s=0;
m=0;
h=0;
//Reset so that it starts again and shows a new day
}
delay(1000);
lcd.clear();

}

Did you try any of the examples that come with the library that you are using to make sure that the LCD works?

Have you tried adjusting the contrast pot?

Does the LCD backlight come on (if it is wired)?

It would help if you tell us which Arduino and LCD. And post a photo of your wiring.

Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

You have attempted to reuse Arduino pins 8 an 9 for hs and ms.
They don't seemed to actually be used other than set to input mode after the lcd library has been told they belong to it.
Remove their use, or pick some other pins for hs and ms.

--- bill