I'm trying to scroll a string in the second row of the LCD while letting the string on the first row stay intact. I use Serial to run that part of the code as you can see. It work at first but when I try to make it run again it doesn't display anything on the second row.
I borrowed the code from :
And made some changes:
// include the library
#include <LiquidCrystal.h>
// init the lcd display according to the circuit
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
// it's a 16x2 LCD so...
int screenWidth = 16;
int screenHeight = 2;
String line1;
String line2;
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;
String CompleteString;
String stringArray[] = {"s=Plane", "i=Car", "h=Boat", "u=Rocket", "d=Jet", "p=Submarine", "l=Truck", "b=Bicycle", "m=Skate", "enter=Train"};
String string1 = "String";
int countMovement=0;
int arraylimit = 9;
void setup() {
lcd.begin(screenWidth,screenHeight);
Serial.begin(9600);
}
void loop(){
char ser = Serial.read();
if ( ser == 'c' ) {
CompleteString="";
for (int i = 0 ; i <= arraylimit; i++) {
CompleteString += stringArray[i] + " "; // Convert String Array To Single String
}
roop(string1,CompleteString);
}
}
void roop(String line1, String line2) {
countMovement = 0;
while ( ( countMovement ) < (line2.length() + screenWidth ) ) {
lcd.setCursor(scrollCursor, 1);
lcd.print(line2.substring(stringStart,stringStop));
lcd.setCursor(4, 0); // 1 = word eat array of words very cool
lcd.print(line1);
delay(300);
lcd.clear();
if(stringStart == 0 && scrollCursor > 0){
// Serial.println(scrollCursor);
scrollCursor--;
stringStop++;
} else if (stringStart == stringStop){
stringStart = stringStop = 0;
scrollCursor = screenWidth;
} else if (stringStop == line1.length() && scrollCursor == 0) {
stringStart++;
} else {
stringStart++;
stringStop++;
}
countMovement++;
}
lcd.setCursor(4, 0);
lcd.print(line1);
}
From what I can see using Serial as debugging is that the problem resides in the function "roop" and in specific the line:
if(stringStart == 0 && scrollCursor > 0){
It seems that the statement is being pass on and so it doesn't move the string as it's suppose to. I could be wrong but placing a Serial call in there yields no result the second time the function is called but the first time it did.
Any help would be much appreciated! And I know the community will be grateful too since it's difficult from what I can see in post to achieve this and make it autonomous so that no big modifications needs to be done.