Pages: [1]   Go Down
Author Topic: LCD  (Read 932 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 88
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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%)


* Untitled.png (36.75 KB, 132x228 - viewed 13 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4265
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or clear the line with spaces first...

Code:
lcd.print("         ");
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 67
Posts: 2521
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or put a couple of spaces on end of line that prints percentage
Code:
lcd.print("%  ");
Logged

Maine
Offline Offline
Sr. Member
****
Karma: 14
Posts: 417
Caution: Explosives in use.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or clear the line with spaces first...

Code:
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."

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

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7189
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if (number<10) lcd.print("  "); // two spaces
if ((number>=10)&&(number<100)) lcd.print(" ");// one space
lcd.print(number);
lcd.print("%");
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18742
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7189
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 smiley-wink
Logged


Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 67
Posts: 2694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All you need it to do this:

Code:
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:
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
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7189
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
Logged


Sydney
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
 
{
  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 Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sydney
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahh, sorry.
Fixed it
Logged

Pages: [1]   Go Up
Jump to: