#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust the I2C address if needed

void displayMessage() {
lcd.clear();

// Display "ECOROOTS" centered on the first row
lcd.setCursor((16 - 8) / 2, 0); // (16 - 8)/2 centers "ECOROOTS" (8 chars) on a 16-char display
lcd.print("ECOROOTS");

String message = "ROOTING SUSTAINABILITY INTO THE FUTURE";

int scrollLength = message.length() - 16;

if (scrollLength <= 0) {
// Message fits on screen, no scrolling needed
lcd.setCursor((16 - message.length()) / 2, 1);
lcd.print(message);
delay(5000);
} else {
int totalScrollSteps = scrollLength + 1; // To account for full scrolling
int delayTime = 5000 / totalScrollSteps; // Time per scroll step

for (int pos = 0; pos <= scrollLength; pos++) {
lcd.setCursor(0, 1);
lcd.print(message.substring(pos, pos + 16));
delay(delayTime);
}
}
}

void displaySearchingMessage() {
lcd.clear();

String message = "SEARCHING ENVIRONMENT FOR DEVICES";

int scrollLength = message.length() - 16;

if (scrollLength <= 0) {
// Message fits on screen, no scrolling needed
lcd.setCursor((16 - message.length()) / 2, 0);
lcd.print(message);
delay(5000);
} else {
int totalScrollSteps = scrollLength + 1; // To account for full scrolling
int delayTime = 5000 / totalScrollSteps; // Time per scroll step

for (int pos = 0; pos <= scrollLength; pos++) {
lcd.setCursor(0, 0);
lcd.print(message.substring(pos, pos + 16));
delay(delayTime);
}
}
}

void displayDeviceFound() {
lcd.clear();
// Display "1 DEVICE FOUND" centered on the first row
lcd.setCursor((16 - 13) / 2, 0); // 13 characters for "1 DEVICE FOUND"
lcd.print("1 DEVICE FOUND");
delay(1000); // Display it for 3 seconds
}

void setup() {
lcd.init();
lcd.backlight();
displayMessage(); // Call the first function
displaySearchingMessage(); // Call the second function
displayDeviceFound(); // Display "1 DEVICE FOUND"
}

void loop() {
// Empty loop
}

For the above code, create the following functionality

Create a function that will display a list of item in a particular manner. This manner is that initially it will display the fist item in the list on line 1 of the LCD I2C display. Line 2, will have the item right after the item in the first list. I have a joystick connected, with code I have uploaded below that determines the movements. As soon as the joystick movement is detected as down, The item on the second line goes to the first line, and the item after this item in the list goes to the second line. Similarly, as soon as the joystick movement is detected as up, The item on the first line goes to the second line, and the item before this item in the list goes to the firs line. Then call this functionin the loop to work on a list of a bunch of fruits

here is the code for the joystick movement

#include <Arduino.h>
#include <U8g2lib.h>


// Define pins for joystick module
const int vryPin = A0; // Y-axis
const int vrxPin = A1; // X-axis
const int buttonPin = 2; // Button

// Variables to store readings, main direction state, and counters
int yValue = 0;
int xValue = 0;
String mainDirection = "Center";
bool isCentered = true;

// Function to center text between pixels 64 and 128 horizontally
int centerText(const char* label, int counter) {
char buffer[20];
sprintf(buffer, "%s: %d", label, counter);

int textWidth = u8g2.getStrWidth(buffer);
return 64 + (64 - textWidth) / 2;
}

int upCounter = 0;
int downCounter = 0;
int leftCounter = 0;
int rightCounter = 0;

// Timing variables for holding in a single direction
unsigned long holdStartTime = 0;
const unsigned long holdIncrementInterval = 500; // 500 milliseconds

void setup() {
Serial.begin(115200); // Initialize Serial for debugging (if needed)

// Set button pin as input with pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
// Read analog values from Y and X axes
yValue = analogRead(vryPin);
xValue = analogRead(vrxPin);

// Determine Y-axis direction
String yDirection = "";
if (yValue > 3000) {
yDirection = "Up";
} else if (yValue < 1000) {
yDirection = "Down";
} else {
yDirection = "Center";
}

// Determine X-axis direction
String xDirection = "";
if (xValue > 3000) {
xDirection = "Right";
} else if (xValue < 1000) {
xDirection = "Left";
} else {
xDirection = "Center";
}

// Determine current direction based on X and Y directions
String currentDirection = "Center";
if (yDirection != "Center") {
currentDirection = yDirection;
} else if (xDirection != "Center") {
currentDirection = xDirection;
}

// Reset main direction to Center if joystick is in idle position
if (currentDirection == "Center") {
isCentered = true;
mainDirection = "Center";
holdStartTime = 0; // Reset the hold time when joystick is centered
}
else if (isCentered) {
// Update main direction if joystick was previously centered
mainDirection = currentDirection;
isCentered = false;

// Increment the counter for the new main direction
if (mainDirection == "Up") {
upCounter++;
} else if (mainDirection == "Down") {
downCounter++;
} else if (mainDirection == "Left") {
leftCounter++;
} else if (mainDirection == "Right") {
rightCounter++;
}

// Start hold timer
holdStartTime = millis();
}
else if (mainDirection == currentDirection && holdStartTime > 0) {
// Check if 500 milliseconds have passed since the last increment
if (millis() - holdStartTime >= holdIncrementInterval) {
// Increment counter again if still holding in the same direction
if (mainDirection == "Up") {
upCounter++;
} else if (mainDirection == "Down") {
downCounter++;
} else if (mainDirection == "Left") {
leftCounter++;
} else if (mainDirection == "Right") {
rightCounter++;
}

// Reset hold timer to count every 500 milliseconds
holdStartTime = millis();
}
}

// Add a small delay to stabilize readings
delay(75);
}

create me code that will do the above.