Sorry, I did not look at the scroll_text function and hence did not realise it is non-blocking.
Change the scroll_text.
////////////////////////////////////////////////
/* 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 scroll is still in progress return false
if (positionCounter[line] == 0 || positionCounter[line] = strlen(text) + LEDLINE - 1)
{
return true;
}
else
{
return false;
}
}
/////////// end of function /////////////////////////////////////////////////
The first line changed to indicate to the compiler that the function will return a bool. The added part at the end indicates to the calling function if one 'scroll' has completed or not.
Next in loop(), test for the return value before incrementing the counter. The code below now uses two counters, one for each line.
void loop() {
// variable to count number of 'scrolls'; one for each line; by default initialised to 0
static byte scrollCount[2];
// Scroll text in line number 0
if (scroll_text("This text is for top line, it is long ", 0) == true)
{
scrollCount[0]++;
}
// Scroll text in line number 1
if (scroll_text("This on bottom", 1) == true)
{
scrollCount[1]++;
}
// if either scrollCount has not reached the number of scrolls
if (scrollCount[0] != 5 || scrollCount[1] != 5)
{
// nothing else to do
return;
}
}