hello everyone, i have a minor problem that i can't solve... maybe you could tell me where i am going wrong...
i am trying to create a digital clock using an arduino uno uc. the clock has to be 00:00:00 form, max being 23:59:59. when the time hits 00:05:10, another 0 appears at the seconds and i don't understand why... i know i could try setting the cursor over that zero and print a space but i don't like the ideea. the zero just stays there.
this is the code i used:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int s=0;
int m=0;
int h=0;
boolean x=false;
#define LED 13
ISR(TIMER1_OVF_vect) {
s++;
if(s==60){
s=0;
m++;
}
if(m==60){
m=0;
h++;
}
if(h>23){
h=0;
}
x=!x;
TCNT1=0x0BDC;
}
void setup() {
lcd.begin(16, 2);
lcd.setCursor(2,0);
lcd.print(":");
pinMode(LED, OUTPUT);
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock
}
void loop () {
if(x==true){
lcd.setCursor(5,0);
lcd.print(":");
}
else{
lcd.setCursor(5,0);
lcd.print(" ");}
seconds();
minutes();
hours();
digitalWrite(LED, x);
}
int seconds(){
lcd.setCursor(6,0);
if(s<10){
lcd.print("0");}
lcd.print(s);
}
int minutes(){
lcd.setCursor(3,0);
if(m<10){
lcd.print("0");}
lcd.print(m);
}
int hours(){
lcd.setCursor(0,0);
if(h<10){
lcd.print("0");}
lcd.print(h);
}
i tried a lot of methods to get rid of that nasty 0, none worked... someone please explain me why this is happening. Waiting for some feedback. Thank you.