Text always center in lcd display

Hi

I have a project that im working on, and the display show some numbers i always want to be in the center. This number start out small, and gets bigger over time. So if i use lcd.setCursor . It will only be in the center for a short while. Is there any code that can do this?

Thanks

So if i use lcd.setCursor . It will only be in the center for a short while. Is there any code that can do this?

Of course. It's called math.

You need to know how many characters you are going to write, so you can divide that number by 2, to get an offset, so you can set the cursor to the center minus the required offset.

Which is exactly what my sister learned at secretarial school 50+ years ago when she had to centre a heading on a manual typewriter.

JimboZA:
Which is exactly what my sister learned at secretarial school 50+ years ago when she had to centre a heading on a manual typewriter.

Your (much) older sister? 8)

Yeah she's a '43, I'm a '56.

I Use this function:

/*
row = Zeile, 0 bis 3
text = Displaytext
ltr = 0 = linksbündig, 1 = mittig, 2 = rechtsbündig
*/
void lcdText(int row, String text, int ltr){

int offset = 0;

switch(ltr){

case(0)://Text links
lcd.setCursor ( offset, row );
lcd.print(text);
break;

case(1)://Text mittig
offset = (displayCharLength - text.length())/2;
lcd.setCursor ( offset, row );
lcd.print(text);
break;

case(2)://Text rechts
offset = (displayCharLength - text.length());
lcd.setCursor ( offset, row );
lcd.print(text);
break;

}
}

void lcdTextClear(int row){
lcd.setCursor ( 0, row ); //select the row
lcd.print(" "); //Clear the row
}