#include <Wire.h> // I2C library
#include <LiquidCrystal_I2C.h> // LCD I2C library
// Define LCDs with different I2C addresses
LiquidCrystal_I2C lcd1(0x27, 16, 2); // LCD 1 at address 0x27
LiquidCrystal_I2C lcd2(0x3F, 16, 2); // LCD 2 at address 0x3F
LiquidCrystal_I2C lcd3(0x20, 16, 2); // LCD 3 at address 0x20
String message = "This is a scrolling message";
int scrollSpeed = 300; // Scrolling speed (milliseconds)
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Begin Serial for debugging
// Initialize each LCD with columns and rows
lcd1.begin(16, 2);
lcd2.begin(16, 2);
lcd3.begin(16, 2);
// Turn on the backlight for each LCD
lcd1.backlight();
lcd2.backlight();
lcd3.backlight();
// Clear each LCD
lcd1.clear();
lcd2.clear();
lcd3.clear();
Serial.println("LCDs initialized and ready.");
}
void loop() {
// Scroll the message through the three LCDs
for (int pos = 0; pos < message.length() + 32; pos++) {
// Clear the LCDs before updating
lcd1.clear();
lcd2.clear();
lcd3.clear();
// Display segments on each LCD based on the current position
if (pos < message.length()) {
lcd3.setCursor(0, 1);
lcd3.print(message.substring(pos, pos + 16)); // Display on row 1 of LCD 3
}
if (pos >= 16 && pos < message.length() + 16) {
lcd3.setCursor(0, 0);
lcd3.print(message.substring(pos - 16, pos)); // Display on row 0 of LCD 3
}
if (pos >= 32) {
lcd2.setCursor(0, 1);
lcd2.print(message.substring(pos - 32, pos - 16)); // Display on row 1 of LCD 2
}
if (pos >= 48) {
lcd2.setCursor(0, 0);
lcd2.print(message.substring(pos - 48, pos - 32)); // Display on row 0 of LCD 2
}
if (pos >= 64) {
lcd1.setCursor(0, 1);
lcd1.print(message.substring(pos - 64, pos - 48)); // Display on row 1 of LCD 1
}
if (pos >= 80) {
lcd1.setCursor(0, 0);
lcd1.print(message.substring(pos - 80, pos - 64)); // Display on row 0 of LCD 1
}
// Debug output
Serial.print("Current scroll position: ");
Serial.println(pos);
delay(scrollSpeed); // Delay for scroll effect
}
Serial.println("Message scrolling completed, restarting...");
}