LCD Display Programming - memory of numbers

Hi

For my university project i am making a wireless winch controller to operate a winch remotely, and have also developed it to give a display of the Battery voltage and number of turns of rope on the winch drum on a LCD display.

For the battery voltage i have taken the analog value from a potentiomenter and multiplied it by 0.01566 to give the range from 0v to 16v.

 lcd.setCursor(10, 0);          //moves cursor to end of equals sign
    lcd.print(analogValue*0.01566);//prints the battery voltage 0-16v

For the number of turns of rope on the drum (Turncount) i have printed the number to the lcd display,

 lcd.setCursor(30,1);           //moves cursor to end of equals sign
        lcd.print(RTurncount);         //prints the number or rear turns

The problem that i have got is when the battery voltage drops from double figures to single figures (10.28v to 9.81v) it keeps the last digit in place so actually prints 9.818v. I have got the same problem with displaying the number of turns of rope on the drum, anything above 10 good but when it drops to 9, 8 7 etc it actually displays "90", "80","70" etc.

How can i get around this problem? i think i am right in saying that it is caused by the digits being shifted to the left and not erasing the previous information that left there.

Many thanks

Tris

How can i get around this problem? i think i am right in saying that it is caused by the digits being shifted to the left and not erasing the previous information that left there.

You are correct. There are a couple of ways to solve the problem. One involves having sprintf() format the string to printed, so that you always get the same number of characters in the string. The other is to simply print a couple of spaces after the number.

To print some spaces after the number is it as simple as changing the following?

from

lcd.print(analogValue*0.01566)

to

lcd.print(analogValue*0.01566  )

Ive tried doing this but i still have the same issue, Have you got any information on the Sprintf() function?

To print some spaces after the number is it as simple as changing the following?

No.

lcd.print(analogValue*0.01566);
lcd.print("  ");

Perfect, Cant believe it was so simple and I have spent so long getting my head around it.

Thanks for your help!