add i2c 16x2 display output

This commit is contained in:
Marcus 2023-08-08 20:36:16 +02:00
parent d220bf426d
commit 472d14b048

View file

@ -5,6 +5,9 @@
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 2
@ -38,7 +41,32 @@ uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 };
uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A };
void setup() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("*fridge control*"); // print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (0, 0)
lcd.print(" by DeltaLima");
delay(1500);
// display default values
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1: H");
lcd.print(HTemp1);
lcd.print(" L");
lcd.print(LTemp1);
lcd.setCursor(0, 1);
lcd.print("2: H");
lcd.print(HTemp2);
lcd.print(" L");
lcd.print(LTemp2);
delay(3500);
// init MOSFET Pins
pinMode(MOSFET1, OUTPUT);
pinMode(MOSFET2, OUTPUT);
@ -48,7 +76,7 @@ void setup() {
}
void loop() {
// get sensor values
sensors.requestTemperatures();
tempSensor1 = sensors.getTempC(addrSensor1);
@ -69,6 +97,30 @@ void loop() {
fetState2 = 0;
}
// LCD Display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1: ");
lcd.print(tempSensor1);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(14,0);
lcd.print("|");
lcd.print(fetState1);
lcd.setCursor(0, 1);
lcd.print("2: ");
lcd.print(tempSensor2);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(14,1);
lcd.print("|");
lcd.print(fetState2);
// JSON
StaticJsonDocument<96> jsonOut;
//jsonOut["sensor"] = "1";
jsonOut["1"]["temp"] = tempSensor1;
@ -79,6 +131,8 @@ void loop() {
jsonOut["2"]["state"] = fetState2;
serializeJson(jsonOut, Serial);
Serial.println();
delay(5000);
}