Hi, I'm new to programming bought an Arduino to create some real-world projects.
I'm trying to code a clock with just a UNO R3 started kit. I'm using the millie() function to keep time. However, after 10 minutes, there is a delay of about a second.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int seconds = 0;
int minutes = 0;
int hours = 0;
unsigned long tSeconds = 1000;
unsigned long recTime = 0;
void setup() {
int hours = 0;
lcd.begin(16, 2);
lcd.print("Clock");
lcd.setCursor(8,1);
lcd.print(" : : ");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
lcd.setCursor(14, 1);
if (seconds < 10){
lcd.print("0");
}
lcd.print(seconds);
lcd.setCursor(11, 1);
if (minutes < 10){
lcd.print("0");
}
lcd.print(minutes);
lcd.setCursor(8, 1);
if (hours < 10){
lcd.print("0");
}
lcd.print(hours);
if (millis() - recTime >= tSeconds){
seconds += 1;
recTime = millis();
}
if (seconds >= 60){
minutes += 1;
seconds = 0;
}
if (minutes >= 60){
hours += 1;
minutes = 0;
}
if (hours >= 24){
hours = 0;
}
}