I use TimedAction do multi-threading,one thread controls first line, another controls second.
In example ,no variable was passed into function,but I have following code, need pass variables to both functions. how can I do ?
/********************************/
// first static line,second scroll line
#include <TimedAction.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/**********************************************************/
LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
/*********************************************************/
String msg = "hallo!";
String info = "this is a message from NASA spacestation!";
void short_msg(String msgs){
for (int i = 0; i < msgs.length(); i++) {
lcd.setCursor(i, 0);
lcd.print(msgs[i]);
delay(150);
}
}
TimedAction firstLine = TimedAction(700,short_msg(msg));
TimedAction secondLine = TimedAction(3000,long_msg(info));
void setup()
{
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
}
/*********************************************************/
void loop()
{
firstLine.check();
secondLine.check();
// short_msg(msg);
// long_msg(info);
}
void long_msg(String msgs) {
int s = 16; //cursor pos
int t = 0; // first char to display
int pad = 0;
for(int r = msgs.length()+16;r>0;r--){
if(s>0){
s--;
}else{
t++;
}
lcd.setCursor(s,1);
if(r<=16){
pad=1;
}
if(s>0){
lcd.print(msgs.substring(0,16-s));
}else{
lcd.print(msgs.substring(t,16+t));
}
if(pad==1){
lcd.print(" ");
}
delay(300);
}
}
compile error like this:
display2:27:55: error: invalid use of void expression
TimedAction firstLine = TimedAction(700,short_msg(msg));
^
display2:28:57: error: invalid use of void expression
TimedAction secondLine = TimedAction(3000,long_msg(info));
^
exit status 1
invalid use of void expression