maybe..
/*
https://forum.arduino.cc/t/lcd-help-coding/1277759
*/
#include <LiquidCrystal.h>
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int photoresistorPin = A0;
const int buttonPin = 7;
bool lightDetected = false; // Flag to track if light is detected
byte buttonPressed = 1; // Flag to track if last button state
String currentText = "text1";
String buttonText = "text2";
//starts with the current text
String displayText = currentText;
//flag to know which text..
byte textFlag = 0;
byte stateSys = 0;
unsigned long lastMove = 0;
unsigned long intervalMove = 2000;
unsigned long lastPress = 0;
unsigned long debounceDelay = 50;
void setup() {
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
pinMode(buttonPin, INPUT_PULLUP);
// Don't print anything initially
}
void loop() {
unsigned long now = millis();
int sensorValue = analogRead(photoresistorPin);
if ( now - lastPress >= debounceDelay) {
byte buttonState = digitalRead(buttonPin);
if (buttonState != buttonPressed) {
//button change, start debouncing
lastPress = now;
buttonPressed = buttonState; // remember
if (buttonState == LOW) {
if (textFlag < 1) {
displayText = buttonText;
textFlag = 1;
} else {
displayText = currentText;
textFlag = 0;
}
if (stateSys > 1) stateSys = 1;
}
}
}
// Adjust this threshold based on your environment
if (sensorValue > 500) {
lightDetected = true;
//only if less than 1, could be scrolling state 2
if (stateSys < 1) {
stateSys = 1;
}
} else {
lightDetected = false;
stateSys = 0;
}
switch (stateSys) {
case 0: lcd.clear(); //no light just Clear the LCD
break;
case 1: lcd.clear(); // Clear the LCD
// Print the message at the beginning of the first row
lcd.setCursor(0, 0);
lcd.print(displayText);
//setup 2 second delay
lastMove = now;
intervalMove = 2000;//delay for static text
stateSys = 2;
break; //light first detect
case 2: if (now - lastMove >= intervalMove) {
lastMove = now;
intervalMove = 1000;// scrolling delay..
lcd.scrollDisplayLeft(); // Scroll the display to the left
}
break;
}
}
~q