#include <Wire.h> #include <LiquidCrystalI2C.h> LiquidCrystalI2C lcd(0x27, 16, 2); //…
- User
#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
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.