I modified it a little bit and add comments. I don't know exactly what your trying to do, but if you want two rows to shift at the same time (or different times) in opposite directions, then this is what you need.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define N_CHARS ((sizeof(MessageOut)/sizeof(MessageOut[0]))-1)
#define N_CHARS2 ((sizeof(MessageOut2)/sizeof(MessageOut2[0]))-1)
LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 16 chars and 2 line display
char MessageOut[21];
char MessageOut2[21];
int index = 19, index2 = 0;
unsigned long oldTime = 0, oldTime2 = 0;
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop()
{
setHeadingRight("Hello", 0, 1000); // message, row, duration (1 second)
setHeadingLeft("Welcome", 1, 500); // message, row, duration (half second)
}
void setHeadingRight(char * msg, byte row, unsigned long duration)
{
strncpy(MessageOut, msg, sizeof(MessageOut));
if(millis() - oldTime > duration) // check the difference of the current time "millis()" to the previous time "oldTime" against the duration you want.
{
oldTime = millis(); // update oldTime with the current time
if(index >= 0) // make sure the index does not go under 0
{
index--; // decrecment index by 1
for (int i = 0; i < N_CHARS; i++) // this part here displays the message on the display
{
lcd.setCursor(i,row); // set the column to show the element in the array
if(index == N_CHARS) index = 0; // set index back to 0 if the index has reached the arrays max size.
if(MessageOut[index++] != NULL) // if the element @ index is anything but NULL, show it.
lcd.print(MessageOut[index-1]);
else
lcd.print(' '); // if the element @ index is NULL, display a space.
}
}
else index = 19; // if index is less than 0, then set it back to 19
}
}
void setHeadingLeft(char * msg, byte row, unsigned long duration2)
{
strncpy(MessageOut2, msg, sizeof(MessageOut2));
if(millis() - oldTime2 > duration2)
{
oldTime2 = millis();
if(index2 < 20) // check to see if index2 is under the array max size
{
index2++; // increment index
for (int i = 0; i < N_CHARS2; i++) // same as above
{
lcd.setCursor(i,row);
if(index2 == N_CHARS2) index2 = 0;
if(MessageOut2[index2++] != NULL)
lcd.print(MessageOut2[index2-1]);
else
lcd.print(' ');
}
}
else index2 = 0; // otherwise set it back to 0
}
}