Go Down

Topic: A very persistant zero on my LCD display (Read 12131 times) previous topic - next topic


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


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




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


I do this for all my LCD outputs.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


Try this:

Code: [Select]


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

lcd.print(value, DEC);


Mar 05, 2012, 11:50 pm Last Edit: Mar 05, 2012, 11:55 pm by John_S Reason: 1

Try this:

Code: [Select]


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: [Select]
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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131