Go Down

Topic: LCD (Read 1 time) previous topic - next topic

liudr

Let's not use the library clear. It clears the whole screen and when used improperly it flickers the screen. All you need it to do this:

Code: [Select]
if (number<10) lcd.print("  "); // two spaces
if ((number>=10)&&(number<100)) lcd.print(" ");// one space
lcd.print(number);
lcd.print("%");

Nick Gammon

Just print two spaces after the number if you don't mind it being left-justified. That will clear any left-over from a previous, larger, number.

liudr


Let's not use the library clear. It clears the whole screen and when used improperly it flickers the screen. All you need it to do this:

Code: [Select]
if (number<10) lcd.print("  "); // two spaces
if ((number>=10)&&(number<100)) lcd.print(" ");// one space
lcd.print(number);
lcd.print("%");



In case you want to switch to zero-padded numbers like 010%, you can just replace space with 0 ;)

bperrybap


All you need it to do this:

Code: [Select]
if (number<10) lcd.print("  "); // two spaces
if ((number>=10)&&(number<100)) lcd.print(" ");// one space
lcd.print(number);
lcd.print("%");


Seems overly complex.
Why not use:
Code: [Select]

if (number <100) lcd.print(" "); // space instead of 100's
if (number < 10) lcd.print(" "); // space instead of 10s
lcd.print(number);
lcd.print("%");


--- bill

liudr

I just assumed whoever asks this type of question only has basic programming skills and try to minimize my time to explain why the code so I wrote in very plain but unoptimized style ;)

Go Up