// https://wokwi.com/projects/412368911755174913
/*
Forum: https://forum.arduino.cc/t/array-of-struct-containing-objects-hd4478-h-lcds-and-list-initialization/1313494
Broken: https://wokwi.com/projects/359393073615174657
See these:
https://wokwi.com/projects/359393073615174657 -- 4 plain LCDs
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>
#include <hd44780ioClass/hd44780_I2Cexp.h>
struct Lcd {
hd44780_I2Cexp dev;
byte cols;
byte rows;
char name[15];
Lcd(uint8_t addr, uint8_t c, uint8_t r, const char *n) : dev(addr), cols(c), rows(r) {
strncpy(name, n, 14);
name[14] = '\0';
}
};
Lcd myArr[] = {
{0x27, 16, 2, "A Hello World"},
{0x24, 16, 2, "B Hello World"},
{0x22, 16, 2, "C Hello World"},
{0x21, 20, 4, "D Hello World"},
{0x20, 20, 4, "E Hello World"},
{0x23, 20, 4, "F Hello World"},
{0x25, 20, 4, "G Hello World"},
{0x26, 20, 4, "H Hello World"},
{0x28, 20, 4, "I Hello World"},
{0x29, 20, 4, "J Hello World"},
};
void setup() {
for (auto &lcd : myArr) {
lcd.dev.begin(lcd.cols, lcd.rows);
lcd.dev.backlight();
lcd.dev.print(lcd.name);
lcd.dev.setCursor(0, 1);
lcd.dev.print("Addr: 0x");
lcd.dev.print(lcd.dev.getProp(hd44780_I2Cexp::Prop_addr), HEX);
};
}
void loop() {
}