#define LCD_SCROLL_SPEED 20
struct Lcd
{
char text[4][21];
char scrollText[4][100];
int scrollIndex[4];
int scroll[4]; //0 don't scroll, count up 500 code loops and then increment scrollIndex
bool updateLine[4];
bool update;
};
struct Lcd lcd;
char test[] = "Main Cue List this is some text which is more than to characters long";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
snprintf(lcd.scrollText[0], 100, "Main Cue List this is some text which is more than to characters long");
lcd.scroll[0] = 1;
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
serviceLcdScroll();
}
void serviceLcdScroll()
{
for (int i = 0; i < 4; i++)
{
if (lcd.scroll[i] > 0)
{
lcd.scroll[i]++;
}
if (lcd.scroll[i] == LCD_SCROLL_SPEED )
{
if (lcd.scrollIndex[i] < strlen(lcd.scrollText[i]) + 19) //scrollIndex runs for the length of the text + length of lcd -1
{
lcd.scrollIndex[i]++;
}
else {
lcd.scrollIndex[i] = 0;
}
for (int j = 0; j < 20; j++)
{
int k = j + lcd.scrollIndex[i];
if (k > strlen(lcd.scrollText[i]) + 19) //keep going until the last character is on the left most character of the screen.
{
k = k - strlen(lcd.scrollText[i])-19;//adjust k to put the first character on the right most character of the screen.
}
if (k >= 20) //fill lcd.text with part of scrollText
{
lcd.text[i][j] = lcd.scrollText[i][k-20];
}
else { //fill lcd.text with spaces
lcd.text[i][j] = ' ';
}
}
Serial.println(lcd.text[0]);
lcd.update = 1;
lcd.scroll[i] = 1;
}
}
}