#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String text[10]; // Array to store text
int numTextElements = 0; // Number of text elements
int currentPage = 0;

void setup() {
    Serial.begin(115200);
    lcd.begin(16, 2);
    lcd.print("Enter text:");
    readInputText();
    printPage();
}

void readInputText() {
    while (Serial.available() == 0) {
        // Wait for user input
    }
    
    String input = Serial.readStringUntil('\n'); // Read input until newline
    int index = 0;
    int start = 0;
    int length = input.length();
    
    while (start < length) {
        text[index] = input.substring(start, min(start + 16, length));
        start += 16;
        index++;
        numTextElements++;
    }
}

void printPage() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(text[currentPage]);
    lcd.setCursor(0, 1);
    lcd.print(text[currentPage + 1]);
}

void loop() {
    switch ((char)Serial.read()) {
        case 'w':
            if (currentPage < numTextElements - 2) {
                currentPage++;
                printPage();
            }
            break;
        case 's':
            if (currentPage > 0) {
                currentPage--;
                printPage();
            }
            break;
    }
}