#include <Wire.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
void lcdSend(byte value, byte mode) {
Wire.beginTransmission(I2C_ADDR);
Wire.write(mode);
Wire.write(value);
Wire.endTransmission();
}
void lcdCommand(byte command) {
lcdSend(command, 0x80);
}
void lcdPrint(char* message, byte line, byte column) {
byte offset = column + (line * LCD_COLUMNS);
lcdSend(offset, 0x80);
while (*message) {
lcdSend(*message, 0x40);
message++;
}
}
void setup() {
Wire.begin();
// Init
lcdCommand(0x33);
lcdCommand(0x32);
lcdCommand(0x28); // 4-bit mode, 2 lines, 5x8 font
lcdCommand(0x0C); // Display on, cursor off, blink off
lcdCommand(0x06); // Increment cursor
// Print something
lcdPrint("Hello, world!", 0, 0);
lcdPrint("Enjoy!", 1, 0);
}
void loop() {
// Your loop code here
}