Pages: [1]   Go Down
Author Topic: LiquidCrystal - Trying lcd[i].print(); without success...  (Read 276 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
« Last Edit: February 14, 2013, 10:06:50 am by reblochon » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
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)
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Here is an example of working code.

Again thank you!!!



Code:
#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(){}
Logged

Pages: [1]   Go Up
Jump to: