Bit new to the arduino game so bear with me...
As part of my project I would like to have a 'start up' screen which displays a few different things, one of which is the time. Got it to display time using a RTC, however, I'm currently using a delay in order to keep the time on the screen for 5 seconds, which doesn't work when displaying seconds as the time is just 'frozen'....
What I want is for a for loop to loop the code below for 5 seconds so that the time shows the seconds 'ticking'. After this 5 seconds is up, the display is cleared so that other stuff can be displayed on the lcd.
lcd.setCursor(1, 3);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" ");
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
Hope this is understandable, thanks in advance!
I don't know which library you are using for time, but you can look at this and try to re-factor for yours:
#include <TimeLib.h>
Stream& lcd = Serial; // comment out and add your LCD library
void setup()
{
Serial.begin(9600);
uint32_t startupMillis = millis();
while(millis() - startupMillis < 6000)
{
displayTime();
}
}
void loop() {}
void displayTime()
{
static time_t lastTime = 0;
time_t t = now();
if(lastTime != t)
{
//lcd.setCursor(1, 3); // uncomment this for LCD
if (hour(t) < 10)
lcd.print("0");
lcd.print(hour(t), DEC);
lcd.print(':');
if (minute(t) < 10)
lcd.print("0");
lcd.print(minute(t), DEC);
lcd.print(':');
if (second(t) < 10)
lcd.print("0");
lcd.print(second(t), DEC);
lcd.print(" ");
lcd.print(day(t), DEC);
lcd.print('/');
lcd.print(month(t), DEC);
lcd.print('/');
lcd.print(year(t), DEC);
lcd.println(); // comment this out for LCD
lastTime = t;
}
}
Simple form:
Use delay(1000) and loop 5 times (e.g. using for loop).
More complicated but more universal:
Remember the last second that display was updated; when current second and last second are different, display the date / time again. Repeat 5 times.