Go Down

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

jonathan_clubine

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

floresta

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


liudr

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.

buracek

Try this:

Code: [Select]

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

John_S

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

Try this:

Code: [Select]

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: [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.
http://jsrintervalometers.blogspot.ca

Go Up