Go Down

Topic: LiquidCrystal - Trying lcd[i].print(); without success... (Read 346 times) previous topic - next topic

Feb 14, 2013, 04:05 pm Last Edit: Feb 14, 2013, 04:06 pm by reblochon Reason: 1
Hi,
Controlling several lcd screen like on this topic works good for me: http://arduino.cc/forum/index.php/topic,5014.0.html. It's fantatic!!!!
But now, I'd like to be abble to select which lcd (lcd0, lcd1, lcd2...etc), with only one variable like i, where i is from 0 to 4.

I tried the following code

Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd0(22, 23, 24, 26, 28, 30);
LiquidCrystal lcd1(22, 25, 24, 26, 28, 30);
LiquidCrystal lcd2(22, 27, 24, 26, 28, 30);
LiquidCrystal lcd3(22, 29, 24, 26, 28, 30);
LiquidCrystal lcd4(22, 31, 24, 26, 28, 30);
char *LCD[5] = {"lcd0", "lcd1", "lcd2", "lcd3", "lcd4"};

void setup()
{
 
for (int i=0; i<=4;i++)
     {
      LCD[i].begin(16,2);
      LCD[i].clear();
      LCD[i].setCursor(0,0);
     }
}

void loop()
{
for (i=0; i<=4;i++)
     {
       LCD[i].setCursor(0,0);
       LCD[i].print("blablabla : ");
       LCD[i].print(i);
     }
}


But the compiler reject it with " request for member 'begin' in 'LCD', which is of non-class type 'char*'".

Is there a way to make it ? Any clue to guide me for that? The need for this is to be abble to select the lcd number with a number in a variable.

Thanks you very much,

Lionel

PaulS

Code: [Select]
char *LCD[5] = {"lcd0", "lcd1", "lcd2", "lcd3", "lcd4"};
That's an array of variable names. In the hex file that the compiler and linker combine to produce, there are no variable names.

You can create an array of LiquidCrystal instances:
Code: [Select]
LiquidCrystal lcds[] =
{
   LiquidCrystal(22, 23, 24, 26, 28, 30),
   LiquidCrystal(22, 25, 24, 26, 28, 30),
   LiquidCrystal(22, 27, 24, 26, 28, 30),
   LiquidCrystal(22, 29, 24, 26, 28, 30),
   LiquidCrystal(22, 31, 24, 26, 28, 30)
}

:smiley-sweat: Thank you Paul!!!! It's beautifull!!!

Here is an example of working code.

Again thank you!!!



Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcds[] =
{
   LiquidCrystal(22, 23, 24, 26, 28, 30),
   LiquidCrystal(22, 25, 24, 26, 28, 30),
   LiquidCrystal(22, 27, 24, 26, 28, 30),
   LiquidCrystal(22, 29, 24, 26, 28, 30),
   LiquidCrystal(22, 31, 24, 26, 28, 30)
};

void setup()
{
 
  for (int i=0; i<=4;i++)
  {
  lcds[i].begin(16,2);
  lcds[i].setCursor(0,0);
  lcds[i].clear();
  lcds[i].print("Yess");
  lcds[i].print(i);
  }
}

void loop(){}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy