Pages: [1]   Go Down
Author Topic: need some help  (Read 222 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please read the stickies at the top of the forum and then re-think the format of your post.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: