Reworked the scroll_text a little bit
////////////////////////////////////////////////
/* this function scrolles the test on top or botoom line on the LCD
according to the line parameter
*/
bool scroll_text(char *text, byte line)
// scroll the LED lines
{
long endScrool = millis() + 5000; //test
char currenttext[LEDLINE + 1];
static unsigned long nextscroll[2];
static int positionCounter[2];
int i;
if (millis() > nextscroll[line])
{
nextscroll[line] = millis() + ledScrollSpeed[line];
for (i = 0; i < LEDLINE; i++)
{
currenttext[i] = charAt(text, positionCounter[line] + i);
}
currenttext[LEDLINE] = 0;
lcd.setCursor(0, line);
lcd.print(currenttext);
if (ledScrollDir[line])
{
positionCounter[line]++;
if (positionCounter[line] == strlen(text) + LEDLINE) positionCounter[line] = 0;
}
else
{
positionCounter[line]--;
if (positionCounter[line] < 0) positionCounter[line] = strlen(text) + LEDLINE - 1;
}
// if scroll was done, return true
if ((ledScrollDir[line] && (positionCounter[line] == 0)) ||
(!ledScrollDir[line] && (positionCounter[line] == strlen(text) + LEDLINE - 1)))
{
Serial.print(line); Serial.print(": "); Serial.println("true");
return true;
}
}
// if scroll is still in progress return false
return false;
}
/////////// end of function /////////////////////////////////////////////////
And I adjusted loop() a little
void loop()
{
static byte scrollCounter[2];
if (scrollCounter[0] < 5)
{
// Scroll text in line number 0
if (scroll_text("This text is for top line, it is long ", 0) == true)
{
scrollCounter[0]++;
Serial.print("0: "); Serial.println(scrollCounter[0]);
}
}
if (scrollCounter[1] < 5)
{
// Scroll text in line number 1
if (scroll_text("This on bottom", 1) == true)
{
scrollCounter[1]++;
Serial.print("1: "); Serial.println(scrollCounter[1]);
}
}
if (scrollCounter[0] < 5 || scrollCounter[1] < 5)
{
return;
}
//lcd.clear();
}
There is a bug somewhere; the last iteration of the second line leaves the 'm' on the screen; did not have time to look at that.