LCD doesn't scroll the full text

So I was trying to build an automatic brightness-controlled greeting display or whatsoever it called. I used 16x2 LCD to display the greeting in two rows. And LDR to control which greeting should be displayed. The changes in LDR value will changes the text displayed. And the text should scrolls to the left. The problem is, for a longer text, it doesn’t displayed the full text. For example from my code “Wake up and get ready. You have an important meeting today.” only displayed as “Wake up and get ready. You have an impo.”. While “rtant meeting today” is missing.
Here is my code:

#include <LiquidCrystal.h>

int lightSensorPin = 0;
int lightSensorVal;
String txtR2;
LiquidCrystal lcd(13,12,11,10,9,8);

void setup() {
lcd.begin(16, 2);

}

void loop() {
lightSensorVal = analogRead(lightSensorPin);

if(lightSensorVal<200){
txtR2 = “Have a sweet dream,my dear.”;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Good night,Amanda.”);
lcd.setCursor(0,1);
lcd.print(txtR2);
for(int i=0; i<txtR2.length(); i++){
lcd.scrollDisplayLeft();
delay(150);
}
}
else if(lightSensorVal>200){
txtR2 = “Wake up and get ready. You have an important meeting today.”;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Good morning,Amanda.”);
lcd.setCursor(0,1);
lcd.print(txtR2);
for(int j=0; j<txtR2.length(); j++){
lcd.scrollDisplayLeft();
delay(150);
}
}
}

Hope any help.

The HD64180 has got two 40-colomn rows i.e. total 80 bytes of Display Memory . You can scroll a 40 character string in hardware.

If you want to scroll an arbitrary length of message, I suggest that you do it in software.

David.