// https://wokwi.com/projects/412368911755174913
/*
Forum: https://forum.arduino.cc/t/array-of-struct-containing-objects-hd4478-h-lcds-and-list-initialization/1313494
XXX this array of structs does not work
See these instead:
https://wokwi.com/projects/412368911755174913 -- Working version with constructor
https://wokwi.com/projects/359393073615174657 -- 4 plain LCDs w/o array
https://wokwi.com/projects/405684473173069825 -- timer/counter using 4 LCDs
Maybe see this for hints:
https://forum.arduino.cc/t/array-of-struct-and-servo-instance-array-initialization-question-for-c/1203322
*/
#include <Wire.h>
#include <hd44780.h> // https://github.com/duinoWitchery/hd44780
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
//hd44780_I2Cexp lcd(0x27); // declare lcd object: auto locate & auto config expander chip
// or autoconfigure:
hd44780_I2Cexp lcdA(0x27); // declare lcd object: explicit address & auto config expander chip
hd44780_I2Cexp lcdB(0x24); // declare lcd object: explicit address & auto config expander chip
hd44780_I2Cexp lcdC; //(0x22); // declare lcd object: auto locate & auto config expander chip
hd44780_I2Cexp lcdD; //(0x21); // declare lcd object: auto locate & auto config expander chip
struct Lcd {
hd44780_I2Cexp & dev; //
byte cols;
byte rows;
char name[];
};
// XXX multiple rows do not work.
// XXX Single, autolocate rows find the first address
Lcd myArr[] = {
// { lcdA, 16, 2, "A Hello World"},
// { lcdB, 16, 2, "B Hello World"},
{ lcdC, 16, 2, "C Hello World"},
// { lcdD, 20, 4, "D Hello World"},
};
void setup()
{
// initialize the LCDs
for ( auto &lcd : myArr) {
lcd.dev.begin(lcd.cols, lcd.rows);
lcd.dev.backlight();
lcd.dev.print(lcd.name);
// print address
lcd.dev.setCursor(0,1);
lcd.dev.print("Addr: 0x");
lcd.dev.print(lcd.dev.getProp(hd44780_I2Cexp::Prop_addr),HEX);
};
}
void loop()
{
// Do nothing here...
}