/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
String data.temperature = " ";
String data.humidity = " ";
// Function to scroll text
// The function acepts the following arguments:
// row: row number where the text will be displayed
// message: message to scroll
// delayTime: delay between each character shifting
// lcdColumns: number of columns of your LCD
void scrollText(int row, String message, int delayTime, int lcdColumns) {
for (int i=0; i < lcdColumns; i++) {
message = " " + message;
}
message = message + " ";
for (int pos = 0; pos < message.length(); pos++) {
lcd.setCursor(0, row);
lcd.print(message.substring(pos, pos + lcdColumns));
delay(delayTime);
}
}
void setup(){
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
//lcd.print("Temp: " + String(data.temperature, 2) + "°C");
//lcd.print("Humidity: " + String(data.humidity, 1) + "%");
//lcd.print("---");
//delay(1000);
// set cursor to first column, first row
lcd.setCursor(0, 0);
lcd.setCursor(0, 1);
// print static message
//lcd.print(messageStatic);
// print scrolling message
scrollText(0, data.temperature, 50, lcdColumns);
scrollText(1, data.humidity, 50, lcdColumns);
}