#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD(0x00, 0, 0); // temporary
String TextLine1 = "";
String TextLine2 = "";
String TextLine3 = "";
String TextLine4 = "";
int t[] = {};
int i = 0;
bool tryConnect(uint8_t address) {
byte error;
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
return true;
}
return false;
}
byte getI2cAddress() {
byte error, address;
for(address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("127/");
Serial.print(address);
Serial.println(" is working!!!");
return address;
} else {
Serial.print("127/");
Serial.print(address);
Serial.println(" is not working");
}
}
return 0;
}
byte lcdAddress;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println("\n"); // new empty line
Wire.begin();
lcdAddress = getI2cAddress();
if (lcdAddress != 0) {
LCD = LiquidCrystal_I2C(lcdAddress, 20, 4);
LCD.begin(20, 4);
LCD.backlight();
LCD.clear();
Serial.println("LCD is started and ready!");
digitalWrite(LED_BUILTIN, LOW);
} else {
Serial.println("LCD isn't started");
digitalWrite(LED_BUILTIN, HIGH);
}
Serial.println("write here");
}
void loop() {
LCD.setCursor(0, 0);
LCD.print(TextLine1);
LCD.setCursor(0, 1);
LCD.print(TextLine2);
LCD.setCursor(0, 2);
LCD.print(TextLine3);
LCD.setCursor(0, 3);
LCD.print(TextLine4);
if (Serial.available()) {
t = [];
i = 0;
while (Serial.available()) {
char data = Serial.read();
t[i] = data;
i++;
}
char data = Serial.read();
if (data != "") {
TextLine1 = TextLine2;
TextLine2 = TextLine3;
TextLine3 = TextLine4;
TextLine4 = String(t);
}
}
}