Go Down

Topic: LCD (Read 2751 times) 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.
I speak for myself, not Arduino.

JimboZA

Or clear the line with spaces first...

Code: [Select]
lcd.print("         ");
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Riva

Or put a couple of spaces on end of line that prints percentage
Code: [Select]
lcd.print("%  ");
Don't PM me for help as I will ignore it.

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

liuzengqiang

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("%");
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

nickgammon

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

liuzengqiang


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 ;)
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

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

liuzengqiang

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 ;)
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

GreenMart

#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.
I speak for myself, not Arduino.

GreenMart

Ahh, sorry.
Fixed it

Go Up