#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTPIN 7
#define DHTTYPE 22
DHT dht(DHTPIN, DHTTYPE);
String slovo = "Teplota", slovicko = "Vlhkost";
unsigned long previousMillis = 0;
byte stupen[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
dht.begin();
lcd.init();
Serial.begin(115200);
lcd.createChar(0, stupen);
lcd.backlight();
lcd.createChar(0, stupen);
lcd.clear();
}
float tep() {
return dht.readTemperature();
}
float vlh() {
return dht.readHumidity();
}
void loop() {
float teplota = tep();
float vlhkost = vlh();
lcd.setCursor(0, 0);
lcd.print(slovo);
lcd.setCursor(16 - String(teplota, 1).length() - 2, 0);
lcd.print(String(teplota, 1));
lcd.write(0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print(slovicko);
lcd.setCursor(16 - String(vlhkost, 1).length() - 1, 1);
lcd.print(String(vlhkost, 1));
lcd.print("%");
lcd.autoscroll();
delay(20)
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 2000) {
previousMillis = currentMillis;
lcd.clear();
}
}