Hello everybody,
I'm writing a short function to enable only one of the lines of a basic 2x16 LCD to scroll, while the other line stay still.
My code is working well in the void() function, but as soon as I try to put it in another function to be called, it stops working.
First of all, the working code :
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 13, 8, 9, 5, 11);
int x;
int y;
void setup() {
Serial.begin(9600);
delay(500);
lcd.begin(16, 2);
lcd.print("Bienvenue");
delay(2000);
}
void loop() {
int pos = 1; // choice of the line
char myMsg[] = "abcdefghijklmnopqrstuvwxyz1234567890";
for (x = 0; x < sizeof(myMsg) - 1; x++){
if (x+y > sizeof(myMsg)-1){break;}
for (y = 0; y < 16; y++){
if (x+y > sizeof(myMsg)-1){break;}
lcd.setCursor(y,pos);
lcd.print(myMsg[x+y]);
}
if (x == 0) {delay(1000);}
delay(200); // speed of scrolling
}
delay(1000);
}
The second line of the LCD screen print "abcdefghijklmnop", wait 1 second, then scroll it for the rest of the chars to appear until "uvwxyz1234567890", then wait another second, and do it again. Great.
Then the code with a second function :
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 13, 8, 9, 5, 11);
int x;
int y;
void setup() {
Serial.begin(9600);
delay(500);
lcd.begin(16, 2);
lcd.print("Bienvenue");
delay(2000);
}
void loop() {
int pos = 1; // choice of the line
char myMsg[] = "abcdefghijklmnopqrstuvwxyz1234567890";
scroll(myMsg,1);
}
void scroll(char msg[], int pos){
for (x = 0; x < sizeof(msg) - 1; x++){
Serial.println(sizeof(msg));
if (x+y > sizeof(msg)-1){break;}
for (y = 0; y < 16; y++){
if (x+y > sizeof(msg)-1){break;}
lcd.setCursor(y,pos);
lcd.print(msg[x+y]);
}
if (x == 0) {delay(1000);}
delay(200);
}
delay(1000);
}
In that case, the LCD screen only show me the first two chars, "ab".
Do you have any idea what is the problem ?
thanks for the help,
Simon