Pages: [1]   Go Down
Author Topic: millis() and lcd.clear() coding  (Read 425 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was wondering if there was a way to use the millis() statement and work it so that it will count seconds and minutes. I tried simple division and statements such as
x = millis();
if ( x == 1000)
   x = 0;
I was also wondering if it was at all possible to erase one character instead of the entire screen from an LCD using the lcd.clear()  statement which out clearing the screen and reprinting everything but the one character i do not want.

Thank you for your input.

Minnesota USA
Offline Offline
Sr. Member
Karma: 1
Posts: 323
Made it mahself outta sand 'n wahr.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

lcd.clear and the underlying hd44780 hardware erase the entire screen. printing a space or a few spaces over the code you want to cover up is faster. clear takes upwards of 2 msec. the hd44780 has to write all of its RAM.

millis is an unsigned long. typically you'd keep track of the starting value at the beginning of the interval you were timing, subtract that from the value of millis at some later time, then divide.

Left Coast, USA
Offline Offline
Sr. Member
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One way: Use lcd.setCursor() to go the part that you want to change.  You can write spaces or whatever new data you want to show.  Leave the rest of the display alone.

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
    lcd.begin(20, 2);
    // This is fixed at the first column of the top row
    lcd.print("Time = 0");

unsigned long secs;     // Automatically initialized to zero
unsigned long old_time; // Automatically initialized to zero

void loop()
    unsigned long now = millis();
    if ((now - old_time) > 1000) {
        lcd.setCursor(7, 0); // Column 8 of first row
        // Also show on serial monitor just for kicks
        Serial.print("Time = ");
        old_time = now;


« Last Edit: August 21, 2010, 07:44:00 am by davekw7x » Logged

Pages: [1]   Go Up
Jump to: