[SOLVED] Changing LiquidCrystal I2C address at runtime

Hello everyone, please can you tell me if it's possible to set the address of the lcd display at runtime?

I have two display with different adress (0x3F, 0x27) and I would like to set the address in the setup, not in the initialization

LiquidCrystal_I2C lcd(0x3F, 20, 4); LiquidCrystal_I2C lcd(0x27, 20, 4);

In this way I can read the address from a configuration file and I don't have to change it manually before sending the sketch to arduino.

I've searched in Arduino-LiquidCrystal-I2C-library-master and Newliquidcrystal_1.3.5 but I haven't found the way to do this.

Thanks, Paolo.

LiquidCrystl_I2C *pLCD = NULL;

void setup()
{
   // Find the desired address, and store it in a byte variable names addr

   pLCD = new LiquidCrystal_I2C(addr, 20, 4);
}

Then, wherever you were using "lcd.", use "pLCD=>" insread.

PaulS:

LiquidCrystl_I2C *pLCD = NULL;

void setup()
{
  // Find the desired address, and store it in a byte variable names addr

pLCD = new LiquidCrystal_I2C(addr, 20, 4);
}




Then, wherever you were using "lcd.", use "pLCD=>" insread.

Thanks, I’m no good with pointers, I’ve tried this sketch

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C *pLCD = NULL;
byte lcdAddress = 39;

void setup()
{
  // initialize the LCD
  pLCD = new LiquidCrystal_I2C(lcdAddress, 20, 4);
  pLCD => begin();

  // Turn on the blacklight and print a message.
  pLCD => backlight();
  pLCD => print("Hello, world!");
}

void loop()
{
  // Do nothing here...
}

and I get this errors

Arduino:1.8.5 (Windows 10), Scheda:“Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”

C:\Users\Maneat\AppData\Local\Temp\arduino_modified_sketch_19280\HelloWorld2.ino: In function ‘void setup()’:

HelloWorld2:11: error: expected primary-expression before ‘>’ token

pLCD => begin();

^

HelloWorld2:11: error: ‘begin’ was not declared in this scope

pLCD => begin();

^

HelloWorld2:14: error: expected primary-expression before ‘>’ token

pLCD => backlight();

^

HelloWorld2:14: error: ‘backlight’ was not declared in this scope

pLCD => backlight();

^

HelloWorld2:15: error: expected primary-expression before ‘>’ token

pLCD => print(“Hello, world!”);

^

HelloWorld2:15: error: ‘print’ was not declared in this scope

pLCD => print(“Hello, world!”);

^

exit status 1
expected primary-expression before ‘>’ token

Questo report potrebbe essere più ricco di informazioni abilitando l’opzione
“Mostra un output dettagliato durante la compilazione”
in “File → Impostazioni”

Ok simple not => but →

Sketch tested ok!

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C *pLCD = NULL;
byte lcdAddress = 39;

void setup()
{
  // initialize the LCD
  pLCD = new LiquidCrystal_I2C(lcdAddress, 20, 4);
  pLCD -> begin();

  // Turn on the blacklight and print a message.
  pLCD -> backlight();
  pLCD -> print("Hello, world!");
}

void loop()
{
  // Do nothing here...
}

Ok simple not => but →

What fat-fingered idiot suggested =>? 8)

PaulS: What fat-fingered idiot suggested =>? 8)

Now you should probably report yourself to the moderator!

Don