simple LCD Scrolltext and Button check

Hi,

I’m starting with a simple project but I did not yet completely understand how Arduino is working.

I want to show some scrolling text on a LCD. Then when a button is pressed I want to show a different scroll text.
Later it should go on like this, when now a Button is pressed once again it should be shown a third message…

How has this be to be handled?

That here is what I already got running. Any ideas how I have to change it to get the described behavior? The button is not working as I would like to.

#include<LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//Variables
String lcdtxt1,lcdtxt2,lcdtxt1a,lcdtxt2a;
int btnOK_Pin = 8;
boolean btnOK = false;
String ScrollTxt(String txt){return txt.substring(1,txt.length()) + txt.substring(0,1);}

void setup(){
//LCD
  lcdtxt1="Welcome";
  lcdtxt2="Please press the OK Button  ";
  lcdtxt1a="ByeBye";
  lcdtxt2a="Thanks for pressing the OK Button";
  lcd.begin(16, 2);
  lcd.clear();
  
//OK-Button
pinMode(btnOK,INPUT);
}



void loop(){

//LCD1 
  lcd.setCursor(0,0);
  lcd.print(lcdtxt1);
  lcd.setCursor(0,1);
  lcdtxt2=ScrollTxt(lcdtxt2);
  lcd.print(lcdtxt2);
  delay(200);


//OK Button -> LCD1a
  if (digitalRead(btnOK_Pin)==HIGH){
  btnOK = false;
  lcd.setCursor(0,0);
  lcd.print(lcdtxt1a);
  lcd.setCursor(0,1);
  lcdtxt2a=ScrollTxt(lcdtxt2a);
  lcd.print(lcdtxt2a);
  delay(200);
  }
}

Thanks Wolle

You need to detect the change from the button off to on. It is the change you are interested in as a trigger to change the message, not whether the button is on.

A few more things: 1. Read about Arrays as this will make this code much easier, especially with storing and changing messages. 2. You will need to debounce the switch as it will give you false triggers otherwise.

You do realise do you not, that these LCDs have very slow response to changes and are not really suitable for scrolling text?