// clean up screen before printing a new reply
lcd.clear();
/* --- first line on LCD --- */
/*** RTC ***/
// set the cursor to LCD column 4, line 0 to center the clock
lcd.setCursor(4, 0);
Straight away, that will cause flicker, right? For a few milliseconds the screen will go blank, and then get gradually redrawn. Why not omit the clear? You could put it in if you are changing display types (eg. from date to temperature) but you don't need to clear the screen every time. So:
Don't call
delay()Don't clear the screen unless changing to displaying a different type of thing
Only update the display at all if the new number (or time, or temperature, etc.) is different from what you just displayed.
Just do the
setCursor()to position the cursor and overwrite the information there previously.Preferably follow by a space or two in case a large number is replaced by a smaller one.
Side-benefit: Since you have removed the delay, your project will now be much more responsive to key presses. Win win!
References
I am not quite sure how to do it
if (RTC.read(tm))
{
static byte oldSecond = 99;
// display if time changes
if (tm.Second != oldSecond)
{
oldSecond = tm.Second;
print2digits(tm.Hour);
lcd.print(':');
print2digits(tm.Minute);
lcd.print(':');
print2digits(tm.Second);
}
}
Similarly further down where you display the date / sensor.