Go Down

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

MostafaHamdy

Code: [Select]
lcd.setCursor(0,2);
lcd.print(line_percentage);
lcd.print("%");


when this code print in LCD give three number such as( 100%)  and when give two number (85%%) and when give  one number (0%%%)
i need to out (100%)  & (85%) & (0%)

AWOL

Why not just print a space in front if 'x' is less than 100 and two if it is less than 10?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

JimboZA

Or clear the line with spaces first...

Code: [Select]
lcd.print("         ");

Riva

Or put a couple of spaces on end of line that prints percentage
Code: [Select]
lcd.print("%  ");
I might seem like an idiot but remember it takes one to know one.
Forum user generally fall into three categories (the good, the bad & the a**hole) what category do you fit in?

wizdum


Or clear the line with spaces first...

Code: [Select]
lcd.print("         ");


Doesn't the liquidCrystal library include a clear function? Something like lcd.clear();?
"Anyone who isn't confused really doesn't understand the situation."

Electronic props for Airsoft, paintball, and laser tag -> www.nightscapetech.com

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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

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

#10
Dec 26, 2012, 01:55 pm Last Edit: Dec 26, 2012, 02:11 pm by GreenMart Reason: 1
Could you try using the modulo operator '%' ?
For example,

Code: [Select]
 
{
  if ((val)%100 < 10) {
    lcd.print(" ");
    lcd.print(val);
  }
  else {
    lcd.print(val);
}


Might have to play around to get it right

AWOL

Quote
Could you try using the modulo operator '%' ?
For example,

The modulo operator is noticeable by its absence in your example.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ahh, sorry.
Fixed it

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!

Arduino
via Egeo 16
Torino, 10131
Italy