This is what I came up with. I modified another users sketch that I had.
You will need to change a few things to get it to work on your screen. Also it would be better if this was made into a class.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define N_CHARS ((sizeof(Compass)/sizeof(Compass[0]))-1)
LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 16 chars and 2 line display
char Compass[21] = {
"N....E....S....W...."};
int index = 19, index2 = 0;
unsigned long time = 0, time2 = 0;
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop()
{
setHeadingRight(0, 1000);
setHeadingLeft(1, 500);
}
void setHeadingRight(byte row, unsigned long duration)
{
if(millis() - time > duration)
{
time = millis();
if(index >= 0)
{
index--;
for (int i = 0; i < N_CHARS; i++)
{
lcd.setCursor(i,row);
if(index == N_CHARS) index = 0;
lcd.print(Compass[index++]);
}
}
else index = 19;
}
}
void setHeadingLeft(byte row, unsigned long duration2)
{
if(millis() - time2 > duration2)
{
time2 = millis();
if(index2 < 20)
{
index2++;
for (int i = 0; i < N_CHARS; i++)
{
lcd.setCursor(i,row);
if(index2 == N_CHARS) index2 = 0;
lcd.print(Compass[index2++]);
}
}
else index2 = 0;
}
}