Following idea:
You have a LCD-display with 2 rows.
You write the first line of a "text" to the second row. Then you clean the screen.
After a delay you write the first line to the first row and a the second line of the text to the second row. Then follows another clean and delay.
Then you write the second line to the first row and the third line to the second row. And so on ...
When the end of the text is reached the whole process starts again from the beginning.
That way the impression of an "vertical moving" text is accomplished.
The code I have written:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setDisplay(String lineValue, int lineNumber, int waitUntilClear, boolean clearScreen) {
lcd.setCursor(0, lineNumber),
lcd.print(lineValue);
delay(waitUntilClear);
if (clearScreen == true) {
lcd.clear();
}
}
void setup() {
lcd.begin(16, 2);
}
void loop() {
const int DELAY = 3000;
const int COUNT_ELEMENTS = 12;
String messages[COUNT_ELEMENTS] = {
"",
"Furniture Store",
" MEYER & MILLER",
"",
" Contact us!",
"",
" -- Email ----- ",
"[email protected]",
"",
" -- Phone ----- ",
" 000 123456",
""
};
for (int i = 0; i < COUNT_ELEMENTS - 1; i++) {
setDisplay(messages[i], 0, 0, false);
setDisplay(messages[i + 1], 1, DELAY, true);
}
}
It works fine and by using an additional function I could avoid code redundancies mostly. If someone has an idea how to improve my code or even doing it completely different in a better way, then I would appreciate his/her comment or answer.
waitUntilClear
is always 0 whenclearScreen
isfalse
then boolean flag is redundant. More than that...you should directly accept both lines (or an array with astartIndex
if you plan to reuse this with different displays). Finally I see too many magic numbers. \$\endgroup\$