Function for writing to multiple I2C LCDs...

Hello arduino gurus and noobs…

I have been trying to solve my problem, unfortunately, for a while now. I would like to have a function which will write to the appropriate I2C LCD based on a functions “String” input parameter. I’m having trouble determining how to code it correctly. Here is the code:

 #include <Wire.h>              // NEEDED FOR THE I2C COMM 
#include <LiquidCrystal_I2C.h> // LCD FUNCTIONS LIBRARY

LiquidCrystal_I2C LEFT_lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
LiquidCrystal_I2C CENTER_lcd(0x26, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
LiquidCrystal_I2C RIGHT_lcd(0x25, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup(){

  LEFT_lcd.begin(20,4);                        //// INITIALIZE THE 20x4 I2C LCD DISPLAY
  CENTER_lcd.begin(20,4);                        //// INITIALIZE THE 20x4 I2C LCD DISPLAY
  RIGHT_lcd.begin(20,4);

}

byte count = 0;
byte state = 0;

void loop(){
  
  String lcd = " ";
  
  if (state == 0){
    lcd = "LEFT_lcd";
      state++;
  }else if (state == 1){
    lcd = "CENTER_lcd";
      state++;
  }else{
    lcd = "RIGHT_lcd";
    state = 0;
  }
  Print_Menu(lcd);
  Cursor_Refresh(lcd);
  
  if(count <= 2)
    count++;
  else
    count = 0;

  delay(10000);

}

void Print_Menu(String lcd){

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("* Smart-Shelf Menu *");
  lcd.setCursor(0,1);
  lcd.print("   Calibrate Product");
  lcd.setCursor(0,2);
  lcd.print("   Calibrate Scale");        
  lcd.setCursor(0,3);
  lcd.print("   Exit");
  
}

void Cursor_Refresh(String lcd){
  if (count == 0){
    lcd.setCursor(0,1);
    lcd.print("-->");
    lcd.setCursor(0,2);
    lcd.print("   ");
    lcd.setCursor(0,3);
    lcd.print("   ");
  } 
  else if (count == 1){
    lcd.setCursor(0,2);
    lcd.print("-->");
    lcd.setCursor(0,1);
    lcd.print("   ");
    lcd.setCursor(0,3);
    lcd.print("   ");           
  } 
  else {
    lcd.setCursor(0,3);
    lcd.print("-->");
    lcd.setCursor(0,2);
    lcd.print("   ");
    lcd.setCursor(0,1);
    lcd.print("   ");
  }
}

Now I understand that the program seems ridiculous. I am trying to solve this problem using a small bit of the total code which I will then incorporate into the much larger code. The error I am getting, pertaining to this code, is:

‘class String’ has no member named ‘clear’
‘class String’ has no member named ‘setCursor’
…and one for all the other function calls which follow.

I believe there is something simple for which I am missing/not doing correctly. Thanks in advance for any help.

I was looking at this example to try to mimic something like this but with little progress. http://forum.arduino.cc/index.php/topic,46910.0.html

I would like to have a function which will write to the appropriate I2C LCD based on a functions "String" input parameter. I'm having trouble determining how to code it correctly.

Because you can't.

Names are converted to addresses when the compiler runs. There is, in the hex file uploaded to the Arduino, nothing called LEFT_lcd.

You certainly can't call methods based on the name of the object.

You could keep track of names and addresses in a struct, and, in the function, convert the name to an address. Iterate through the struct, comparing the passed in name to the stored name, and use the address in the position that corresponds to that of the name in the struct.

But, why bother. It would be simpler to create the objects in the first order, and use numbers (0, 1, 2 or #define statements).

Or, create an array of objects, and pass the index to the function that cares.

The LCDs all have the same I2C address? Use an I2C mux and route the data to the correct part. The array method certainly would work well with that if you have 2 IO pins to spare. http://www.dsscircuits.com/index.php/i2c-multiplexer

PaulS, thank you very much for your reply. Now, I have more research to do.

CrossRoads, each LCD currently has a separate address but I could change this back to the original setting of having the same address and use a multiplexer. Its an interesting work around for my problem but I will attempt PaulS's method first.

It seems like something like this "should be able" (ideally) to be accomplished due its ability to reduce code size significantly. All of my LCDs use 90% of the same info and they are 20x4 with basically all the spaces being used! Blah! Google.com... here I come

Thank you both for the help and if anyone else has any suggestions i would love to hear them.