lcd.print problem

Hi all,

This is my first post, got the Arduino starter kit a couple of days ago and have been working through the projects. i decided i wanted to challenge myself and came up with the idea to control a servo with a potentiometer and have the angle it is at displayed on an lcd.

all went well breadboarding it and it works fine except for the display, i have it so it says [Angle: 0] on start up and will increase up to [Angle: 178] just like i want.

but the problem comes when i decrease the angle, it will keep 2 digits if it has been into double figures or three if triple.

for example; if i move the servo up to 100 then back to 0 it will display [Angle: 027] (the last 2 digits seem random, never the same)

i dont think i have explained it very well sorry.

the code i have for this in loop is:

void loop(){
potVal = analogRead(potPin);
Serial.print(" Pot Val: ");
Serial.print(potVal);
deg = map(potVal, 0, 1023, 0, 178);
Serial.print(" Angle: ");
Serial.print(deg);
lcd.setCursor(0, 0);
lcd.print("Angle: ");
lcd.setCursor(7, 0);
lcd.print(deg);
myServo.write(deg);
delay(15);
}

lcd.setCursor(7, 0);
  lcd.print(deg);
  lcd.print("  ");

Where are those square brackets in your examples coming from ? They are not printed in the code you posted.

sorry thats my fault, that was to just to show there was nothing before or after, they are not on the screen.
im finding it hard to explain myself sorry.

Note that beside the question, UKHeliBob gives the answer to your problem. Write a black space after your degree and your sketch will be just fine.

thanks guys :smiley: simple as that.

Write a black space after your degree and your sketch will be just fine.

Well, a blank space would work better... 8)

PaulS:
Well, a blank space would work better... 8)

:-[

GuzzDan:
thanks guys :smiley: simple as that.

Yes !
Your next assignment is to print leading zeroes on the numbers so that they are always 4 digits in length....