Chri's BLOG

Rants, Reviews, Thoughts and Info

Center Text on Arduino LCD

I had a problem recently that I was trying to find a function or some code in order to center text on any of those LCD’s you can buy to use with your Arduino.

I found one post – and that was only marginally helpful.

So – TL;DR – here you go:

Replace ’20’ with the character length of your LCD – most are 16 or 20.

wherePrint = (20 - (strlen(yourstring)) / 2;
lcd.setCursor(wherePrint, 1);
lcd.print(yourstring);

I hope this helps you guys!

May 24, 2021 Posted by | Computers | Leave a comment