I want tried to make a programm to display a text on an I2C LCD-Display. The text should be scrolled for one position every time the function is called.
On the internet I saw a lot of solutions but there were all diffrent from what I need.
So I tried to make my own code. The code works well except of the part where I try to scroll in the Text from the left.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
char Str[12] = {'T', 'r', 'u', 'e', 't', 'z', 's', 'c', 'h', 'l', 'e', 'r'};
int pos = 0;
int posretry = 0;
bool ledon = false;
void setup()
{
pinMode(13, OUTPUT);
lcd.init();
lcd.backlight(); //lcd.noBacklight();
}
void scroll()
{
for (int i = 0; i < 12; i++)
{
//Print text
lcd.setCursor(i + pos, 0);
lcd.print(Str[i]);
//Move in text from the left
if (pos >= 6)
{
lcd.setCursor(i + pos, 0);
lcd.print(Str[i]);
lcd.setCursor(posretry, 0);
lcd.print(Str[11 - posretry]);
posretry++;
}
}
delay(500);
lcd.clear();
pos++;
}
void changeled()
{
if (ledon == false)
{
digitalWrite(13, LOW);
}
else
{
digitalWrite(13, HIGH);
}
ledon = !ledon;
}
void loop()
{
scroll();
changeled(); //Example Event
}
The goal is to move the text to the right and show the not displayed letters on the left.
Example:
|er Truetzschl| -->
| |
A Video about the error can be found here: https://data.jonas-heinze.de/shares/stackexchange/lcd/
Thanks for your help.
if(pos>=6)
? Do you really needposretry
(for what)? A serious problem is that you never resetpos
andposretry
, so they will exceed the allowed range and even become negative when the int overflows itself. Definitely not right