/*
Arduino | coding-help
one scroll line + one static line on I2C LCD1602 screen
Giratina Musics(Road 2 Polyglot)
December 10, 2025 at 5:38 PM
https://forum.arduino.cc/t/16x2-lcd-one-line-scrolling-one-stationary/406501
*/
#include <LiquidCrystal_I2C.h>
const char firstLine[16] = "Static 1st line";
const char secondLine[39] = "Scrolling text on second line";
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
//lcd.print(firstLine);
}
void loop() {
lcd.clear();
//lcd.setCursor(0, 0);
lcd.print(firstLine);
lcd.setCursor(0, 1);
for (int i = 0; i <= 16; i++) { //For the first 16 characters, simply print them to the LCD screen.
lcd.write(secondLine[i]);
}
delay(1500); //Delay for 1.5 seconds so the user has time to read.
for (int j = 17; j <= 39; j++) { //Now we begin printing from character 17 onward...
lcd.write(secondLine[j]); //Write the j-th character (for now it will be off-screen).
lcd.scrollDisplayLeft(); //Scroll the text left one character-space.
//This is where things get tricky, because both rows will be scrolled. But we want row 1 to remain stationary!
lcd.setCursor(j - 16, 0); //Set the cursor to the first character space on the first row [visually].
// cursor space (0,0) has been scrolled off-screen!
lcd.print(firstLine); //Re-print the row 1 message.
lcd.setCursor(j + 1, 1); //Set the cursor one character space to the right of the last printed character on row 2.
// Which is visually one character space off-screen, in preparation for the next itteration.
delay(300); //delay for .3 seconds so the user has time to read.
}
}