Offline
Jr. Member
Karma: 0
Posts: 87
|
 |
« on: December 24, 2012, 05:50:03 am » |
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%)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: December 24, 2012, 05:51:54 am » |
Why not just print a space in front if 'x' is less than 100 and two if it is less than 10?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Johannesburg UTC+2
Offline
Edison Member
Karma: 34
Posts: 1705
|
 |
« Reply #2 on: December 24, 2012, 06:02:01 am » |
Or clear the line with spaces first... lcd.print(" ");
|
|
|
|
|
Logged
|
IT Crowd: Roy... "Have you tried turning it off and on again?" Moss.. "Have you tried forcing an unexpected reboot?"
|
|
|
|
Norfolk UK
Offline
Edison Member
Karma: 23
Posts: 1313
|
 |
« Reply #3 on: December 24, 2012, 06:32:47 am » |
Or put a couple of spaces on end of line that prints percentage lcd.print("% ");
|
|
|
|
|
Logged
|
|
|
|
|
Maine
Offline
Sr. Member
Karma: 7
Posts: 320
Caution: Explosives in use.
|
 |
« Reply #4 on: December 24, 2012, 01:04:26 pm » |
Or clear the line with spaces first... lcd.print(" "); Doesn't the liquidCrystal library include a clear function? Something like lcd.clear();?
|
|
|
|
|
Logged
|
"Anyone who isn't confused really doesn't understand the situation." Arduino-based airsoft props -> www.nightscapetech.com
|
|
|
|
Central MN, USA
Online
Faraday Member
Karma: 35
Posts: 5914
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #5 on: December 24, 2012, 01:46:40 pm » |
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("%");
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #6 on: December 25, 2012, 03:26:37 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Online
Faraday Member
Karma: 35
Posts: 5914
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #7 on: December 25, 2012, 07:08:15 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Dallas, TX USA
Offline
Edison Member
Karma: 24
Posts: 1615
|
 |
« Reply #8 on: December 25, 2012, 11:28:45 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Online
Faraday Member
Karma: 35
Posts: 5914
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #9 on: December 26, 2012, 12:00:46 am » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Sydney
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #10 on: December 26, 2012, 07:55:01 am » |
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
|
|
|
|
« Last Edit: December 26, 2012, 08:11:16 am by GreenMart »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19001
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: December 26, 2012, 08:04:36 am » |
Could you try using the modulo operator '%' ? For example, The modulo operator is noticeable by its absence in your example.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Sydney
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #12 on: December 26, 2012, 08:11:51 am » |
Ahh, sorry. Fixed it
|
|
|
|
|
Logged
|
|
|
|
|
|