digital clock with arduino

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);
  }

Some help would be nice. Thank you

You’re best off formatting the time into a char array string using sprintf:

char timestr[10];

sprintf(timestr, "%02d:%02d:%02d", h, m, s);
lcd.print(timestr);

thank you very much.

  seconds();
  minutes();
  hours();

These function names do not imply, in any sense, what the functions actually do. They need to be renamed.

  if(x==true){

The==truebitisnotneeded.Thisstatementisequivalentto

  if(x){

from which you can see that x is a lousy name. It says nothing about what the variable is controlling. I hope you can also see that spaces are a good thing.

well the x part was made for the : from the seconds to blink. and the seconds() minutes() hours() first time were used to display s,m,h. using

char timestr[10];

sprintf(timestr, "%02d:%02d:%02d", h, m, s);
lcd.print(timestr);

really made it easier. i am kind of a beginner in programming, don't know too much. trying to learn as many. tested the clock in this morning and at like 53 minutes got a delay for seconds, it was +1. i compare the clock with the analog one from the laptop, not sure if any of these are stable :~

I use the Time library from the playground http://playground.arduino.cc/Code/time displaying time on a 4.3" GLCD. It can be used without time sync but something like a DS1307 or for better accuracy a Chronodot or DS3231. I also display RH, Barometric pressure and Temperature. After the little bragging.. The time library has a lot to offer, Alarms, Month short and long as well as day both short and long (Mon , Monday). Easy to use too with examples. There is a correction variable that can be used to 'correct' for the resonator.. or crystal inaccuracy. GMT is the nominal time zone but any can be used by changing the offset variable The DS1307 can be purchased from Ebay as well as Adafruit, Sparkfun or our Terry King at http://yourduino.hosted.phplist.com/lists/lt.php?id=fB0FAB0JTQcHVgU%3D.

Bob

i might need a little more help. the clock must have the ability to set the time, hours, minutes and even seconds... i am trying to think of way that when i press a button to be send in a "menu" where i use other two buttons to increase/decrease the values(i would like to have the blinking animation while setting the values), and after the operation is done the program must use the new values and return to the clock. i was thinking of using a switch case but i don't know how to return those values after switch case is over. also i don't know if the timer should stop when i am setting up the values... some suggestions would be very helpful. my programming knowledge is not very advanced so if you could give me some simple examples i would be grateful.