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%)
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%)
Why not just print a space in front if 'x' is less than 100 and two if it is less than 10?
Or clear the line with spaces first...
lcd.print(" ");
Or put a couple of spaces on end of line that prints percentage
lcd.print("% ");
JimboZA:
Or clear the line with spaces first...lcd.print(" ");
Doesn't the liquidCrystal library include a clear function? Something like lcd.clear();?
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:
if (number<10) lcd.print(" "); // two spaces
if ((number>=10)&&(number<100)) lcd.print(" ");// one space
lcd.print(number);
lcd.print("%");
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: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
liudr:
All you need it to do this: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:
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
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
Could you try using the modulo operator '%' ?
For example,
{
if ((val)%100 < 10) {
lcd.print(" ");
lcd.print(val);
}
else {
lcd.print(val);
}
Might have to play around to get it right
Could you try using the modulo operator '%' ?
For example,
The modulo operator is noticeable by its absence in your example.
Ahh, sorry.
Fixed it