Go Down

Topic: need some help (Read 334 times) previous topic - next topic

altaier

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.

majenko

Please read the stickies at the top of the forum and then re-think the format of your post.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

altaier

i re-edited the post with a new title and how it should be, sorry for any inconveniences. this post can be deleted.

Nick Gammon

He means code tags.


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.


Read this before posting a programming question

Go Up