#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 or 0x3F (depends on your module)
LiquidCrystal_I2C lcd(0x27, 16, 2);
String message = "Hello, This is LCD Scrolling Demo! "; // Add spaces for smooth scroll
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("LCD Scroll Modes");
delay(2000);
lcd.clear();
}
void loop() {
// 1. LEFT SCROLL
lcd.setCursor(0, 0);
lcd.print("Left Scroll --->");
lcd.setCursor(0, 1);
lcd.print("Scrolling...");
delay(1000);
for (int i = 0; i < 16; i++) {
lcd.scrollDisplayLeft();
delay(300);
}
lcd.clear();
delay(1000);
// 2. RIGHT SCROLL
lcd.setCursor(0, 0);
lcd.print("<--- Right Scroll");
lcd.setCursor(0, 1);
lcd.print("Scrolling...");
delay(1000);
for (int i = 0; i < 16; i++) {
lcd.scrollDisplayRight();
delay(300);
}
lcd.clear();
delay(1000);
// 3. MARQUEE SCROLL (continuous text movement)
lcd.setCursor(0, 0);
lcd.print("Marquee Scroll:");
delay(1000);
for (int pos = 0; pos < message.length(); pos++) {
lcd.setCursor(0, 1);
lcd.print(message.substring(pos, pos + 16)); // show 16 chars at a time
delay(300);
}
lcd.clear();
delay(1000);
// 4. BOUNCE SCROLL (left-right loop)
lcd.setCursor(0, 0);
lcd.print("Bounce Scroll:");
String text = " BOUNCE DEMO ";
int textLen = text.length();
for (int repeat = 0; repeat < 2; repeat++) { // bounce twice
// Move left
for (int i = 0; i <= 16 - textLen; i++) {
lcd.setCursor(i, 1);
lcd.print(text);
delay(300);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bounce Scroll:");
}
// Move right
for (int i = 16 - textLen; i >= 0; i--) {
lcd.setCursor(i, 1);
lcd.print(text);
delay(300);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bounce Scroll:");
}
}
lcd.clear();
delay(2000);
}