#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// I2C things.
byte i2c_rcv;
// List o things
enum {
DEV_CMD_INIT = 0x01,
DEV_STATUS_ACK,
DEV_STATUS_NACK
};
// I2C device.
typedef struct {
int address;
bool ready;
char* name;
} i2c_device;
i2c_device devList[] = {
(i2c_device){0x22, false, "LED Status Chip"}
};
// Init and connect.
bool initializeSystem() {
// Loop through and init devices.
for(int i=0; i<sizeof(devList); i++) {
lcd.clear();
Wire.beginTransmission(devList[i].address);
Wire.write(DEV_CMD_INIT);
Wire.endTransmission();
Wire.requestFrom(devList[i].address, 1); // Read 1 byte
if(Wire.available()) {
i2c_rcv = Wire.read();
}
// Handle device init.
switch(i2c_rcv) {
case DEV_STATUS_ACK:
lcd.print(devList[i].name);
break;
case DEV_STATUS_NACK:
lcd.print("Nope no sir");
break;
}
}
}
void setup() {
Wire.begin();
// Init 16x2
lcd.begin(16, 2);
// Turn on the BL
lcd.setBacklight(HIGH);
// Init message
lcd.print("Initialize");
// Init
initializeSystem();
}
void loop() {
// put your main code here, to run repeatedly:
}