how do I clear extra digits without the flashing of the LCD

Thanks to the help of this forum, I am well on my way to finishing up my project, but I have ran into a minor issue that I cant quite figure out. I am building an antenna rotator, and it uses a 10 turn pot inside of the rotator case to track the direction degrees. I have mapped the pot to run from -20 to 469, this is what works for my gear set. The issue is that if the pot runs into the negative zone, the display is not clearing the digits, so the trailing zeros stay on the display, and once I get into the positive numbers, it leaves the trailing 1 and 0 from "-1" , so when the display should show 1, it shows 110, when it should show 2, it shows 210, 3 is 310... all the way up to 99, which is printed as 990. I set a delay, and added lcd.clear(), but that makes the screen flash. is there another way to eliminate the trailing numbers without having the screen flicker?

Instead of clearing the LCD, just pad the number with trailing spaces.

For example:

char buffer[10]; sprintf(buffer, "%d ", num); // 4 trailing spaces lcd.print(buffer);

thanks, that worked perfect. Jake

Just printing extra spaces after the number doesn't create a buffer with a fixed number of characters. In fact there is no need to use sprintf() to do that. you could have just done:

lcd.print("    );

and saved about 2k of code space. But because of the variable number of characters created in the formatted string, it is possible that, the output string may overflow the alloted field width on the display and either clobber other characters on the display or overflow the display row.

However, if you are going to use sprintf() why not use it's formatting power? i.e. Why just print blank spaces after the digits when you can tell it your desired formatting width and wether to left or right justifiy the number inside the field?

for example:

sprintf(buffer, "%4d", num); // 4 character  decimal number field right justified
sprintf(buffer, "%-4d", num); // 4 character decimal number field left justified

--- bill