Pages: [1]   Go Down
Author Topic: LCD Blinking on second line  (Read 756 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys, I've just started playing with arduino + LCD
i'm trying to build a clock + temperature sensor using arduino.

the lcd display is updating every sec, but the problem is that the second line keeps blinking when it refreshes.

anyone could help me solve this?

I've made a movie so you know what i'm talking about:
http://flickr.com/photos/pasteler0/2726462259/

the code i'm using is this:

Code:


#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(2);

int second=20, minute=10, hour=14, i=0; //start the time on 00:00:00
char buf[12];

int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature

void setup() {
  lcd.init();
  pinMode(11,OUTPUT);
}

void loop() {  
 
  digitalWrite(11,HIGH);
  
  static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
// move forward one second every 1000 milliseconds

        if (millis() - lastTick >= 1000) {
      lastTick = millis();
      second++;
        serialOutput();
  }
        if (second >= 60) {
      minute++;
      second = 0; // reset seconds to zero

  }
        if (minute >=60) {
      hour++;
      minute = 0; // reset minutes to zero
  }

        if (hour >=24) {
      hour=0;
      minute = 0; // reset minutes to zero
  }


}

void serialOutput() {
 
  tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
  
  lcd.clear();
  lcd.printIn("Hora: ");  
  lcd.printIn(itoa(hour, buf, 10));lcd.printIn(":");
  lcd.printIn(itoa(minute, buf, 10));lcd.printIn(":");  
  lcd.printIn(itoa(second, buf, 10));
  lcd.cursorTo(2, 0);
  lcd.printIn("Temp: ");
  lcd.printIn(itoa(tempc, buf, 10));
  
  tempc = 0;

}


« Last Edit: August 02, 2008, 11:04:20 pm by dansku » Logged

Las Vegas, NV
Offline Offline
God Member
*****
Karma: 0
Posts: 507
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Replace your lcd.clear() with whatever function returns the cursor to home position without clearing it (I'm guessing lcd.cursorTo(1, 0) would work).  Then just overwrite the current characters with your new ones.  This should stop the flicker, which I'm thinking results from the delay between when the characters are cleared and the time it takes you to write them back (this is why you see it influencing later characters more significantly).

Note that if your newly printed string is shorter than the previous one, this technique will leave old characters on the screen.  You can deal with this by printing extra blank characters (spaces) to overwrite (erase) characters that should no longer be there.

- Ben
Logged


0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, it worked, thanks mate! smiley-grin
Logged

Pages: [1]   Go Up
Jump to: