#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
char textText[] = "LCD";
byte textSize = sizeof(textText), scrollWidth = LCD_COLUMNS - textSize, column, sign = 1, row = 0;
int wait = 50;
bool toggle = 0;
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
if (column > scrollWidth - 1) { // leave one leading space
column = 0; // reset column
toggle = !toggle; // change direction and row
sign = -sign; // sign of column change
lcd.clear(); // clear stray character
}
lcd.setCursor(((scrollWidth) * toggle) + column * sign, toggle); // set LCD cursor
if (!toggle) // left to right
lcd.print(" "); // trailing space on left
lcd.print(textText);
if (toggle) // right to left
lcd.print(" "); // trailing space on right
delay(wait);
column++; // next column
}