Im having problems with an LCD not showing the correct numbers, it shows 640% instead of 64% , so there's an extra 0
ok.. This is the regular LCD screen
Blue:100% White:100% ( 3 digit number and no empty spaces)
But just after the "X" function starts, the "%" character stays at the same place, like this:
Blue:99 % White:99 % (2 digit number and one empty space)
So the main problem is that im getting 990% instead of 99%
Is there a way to write a code to do something like this:
So the idea would be that if a 3 digit number changes into a two digit number , something between 1 and 99 then, print the LCD with both numbers and add the "%" character just next to the two digit number, like this:
Blue:99% White:99%
Blue:10% White:20%
So in that case I wouldnt have an extra 0, because it would be covered by the "%" character.
I think the problem is due to an extra space between the characters..
Im sorry... I think It could be hard to debug the whole code and I don't want to bother people, that's why I asked that.. but what do I need to post to get an advice?
thanx in advance
badstraw360:
Im sorry... I think It could be hard to debug the whole code and I don't want to bother people, that's why I asked that.. but what do I need to post to get an advice?
thanx in advance
Read the how to use this forum sticky post.
We need enough code to reproduce your problem then we can see where you are going wrong. This is not a problem people normally have.
Create a small program that shows the problem. You should be able to do this in few lines of code, most of which you can copy from your original.
What cursor positioning commands do you have when printing, do you clear the screen before printing, do you clear the line before printing, do you clear the area to be used before printing, are you printing a variable or text, what type is the variable ? We can see none of this at the moment.
Why do you position the cursor to column 8 no matter how many digits there are in the number before printing the % ? Why not just print the number, however big it is, then print the % ?
Print the number first and then print a % sign. What is wrong with that
If you print 100%, then 99%, the display shows 99%%.
There are several ways to solve the problem. Using sprintf() for formulate the string with a fixed number of characters is the simplest. Others require slightly more lines of code but result a smaller overall sketch.
Whatever you do, keep in mind that you'll need to deal with the value dropping below 10, too.
Not quite as correct but an old and simple hack from green screen days
lcd.setCursor(5, 0);
lcd.print(map(ledVal, 0, 255, 0, 100));
//Just print 2 extra spaces after the % sign
lcd.print("% ");
That is all. You do not need set the cursor any differently for 1% or 100%
The problem is that when you print to the LCD it does not clear to the end of line.
You know your number is between 1 and 3 digits, so printing 2 spaces after the % will over write any characters left from the last run through.