Adding a blank space to a created value

Hey Folks,

lcd.SetCursor(5,1);
lcd.print(theNote);

theNote is a created midi value (0-127). How can I add a blank space behind this value? The problem I have is that once the value was over 100, the third place on my LCD stays without changing, even if the value goes under 100 again.

Example:

1) The Midi Note is 118. My Display shows "11*8". 2) The Midi Note now is 76. My Display shows "768". The number "8*" of the first midi value is still being displayed! So how can I force my LCD to clear this third place of the number once the value goes below 100 again (blank space?)?

Thanks for your help in advance!

Happy New Year, Marl

You have the same problem when going from 10 to 9.

You have to decide if you want leading or trailing spaces and print them as needed. i.e. if the value is under 100 print a space, if the value is under 10 print a space.

this will insert the needed space(s) to create a fixed width output.

Do each if & print either before or after you print the value to insert the extra space(s).

--- bill

Thanks for your prompt reply!

As I'm kind of a beginner when it comes to programing, I still need your or one elses help on how to put that into code!?

Thanks in advance, Marl

lcd.setCursor(5,1);
if (theNote < 10) lcd.print(" ");
if (theNote < 100) lcd.print(" ");
lcd.print(theNote);

Thanks Bodmer for helping me,

this works perfectly well!

Marl

A cunning tip I saw elsewhere is to put that into a function, call it say print3. Then whenever you want to do that, and it may be required elsewhere in your sketch, you just use it over and over.

So you have a function like this:

void print3(number)
{
if (number < 10) lcd.print(" ");
if (number < 100) lcd.print(" ");
lcd.print(number);
}

And when you want to use that way you say:

lcd.setCursor(5,1);
print3(theNote);