Pages: [1]   Go Down
Author Topic: A very persistant zero on my LCD display  (Read 3324 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've just started playing with LCD displays, the problem I'm having is probably a simple one but I just don't see it.
I'm printing an analog value, when the value drops to single digits the zero from the ten doesn't clear from the display. Eg. A value of 7 shows as 70.
I've tried "delay(xxx);
                   lcd. clear();"
This creates an annoying flicker.
And mapping the value " 00-100 " with no luck.

Please help, thanks
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 35
Posts: 4299
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Once you write a character to the LCD it stays there until it is overwritten. 
To 'erase' a character you have to overwrite it with a 'space'. 

The best way to deal with displaying changing data is to:
(1) position the cursor
(2) display enough spaces to cover up all of the earlier data
(3) reposition the cursor
(4) display your new data

lcd.clear is not a good choice because (1) it takes a long time and (2) it may cause flicker (as you have seen).


Don
Logged

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

Ill give that a try, thanks.
Logged

Central MN, USA
Online Online
Tesla Member
***
Karma: 73
Posts: 7187
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a tutorial of using the function sprintf to do what Don mentioned in step 2:

http://liudr.wordpress.com/2012/01/16/sprintf/

I do this for all my LCD outputs.
Logged


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

Try this:

Code:
lcd.setCursor(0,0);

lcd.print("Value  : ");                                                                                         
if (value < 10) lcd.print("   ");                 
else if (value < 100) lcd.print("  ");
else if (value < 1000) lcd.print(' ');

lcd.print(value, DEC);
Logged

Canada
Offline Offline
Sr. Member
****
Karma: 0
Posts: 318
Sometimes teaching, always learning,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:

Code:
lcd.setCursor(0,0);

lcd.print("Value  : ");                                                                                        
if (value < 10) lcd.print("   ");                  
else if (value < 100) lcd.print("  ");
else if (value < 1000) lcd.print(' ');

lcd.print(value, DEC);

Or slightly shorter/cleaner:
Code:
lcd.print("Value  : ");                                                                                        
if (value < 1000) lcd.print(" ");
if (value < 100) lcd.print(" ");
if (value < 10) lcd.print(" ");                  

lcd.print(value, DEC);
You will notice that your compiled program is shorter with this method. The compiler treats "   ", "  ", and " " as separate strings, so you will save 2 bytes (by my testing) this way.
« Last Edit: March 05, 2012, 05:55:57 pm by John_S » Logged


Pages: [1]   Go Up
Jump to: