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:
#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;
}