#include <LiquidCrystal_I2C.h> //memasukan library LCD I2C
LiquidCrystal_I2C lcd(0x27, 16, 2); //Setting alamat I2C dan ukuran LCD
char * LargeText = " RAFIF PUTRA HADITAMA EK2D/16 "; // Tulisan baris ke 2
int iLineNumber = 0; // Line number to show your string (Either 0 or 1)
int iCursor = 0;
#include "DHT.h"
#define DHTPIN 0 // DHT PIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
byte suhu1[] =
{
B00000,
B01110,
B01010,
B01010,
B01010,
B10001,
B10001,
B01110
};
byte suhu2[] = {
B00000,
B01110,
B01110,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte api1[] = {
B00000,
B00000,
B00100,
B01110,
B11011,
B10001,
B10001,
B01110
};
byte api2[] = {
B00000,
B00000,
B00100,
B01110,
B11111,
B11111,
B11111,
B01110
};
void setup() {
lcd.init(); //memanggil lcd I2C
lcd.backlight(); //menyalakan backlight LCD
dht.begin(); //memulai DHT
lcd.createChar(1, suhu1);
lcd.createChar(2, suhu2);
lcd.createChar(3, api1);
lcd.createChar(4, api2);
}
void loop() {
delay(1000);
float h = dht.readHumidity(); //membaca kelembaban
float t = dht.readTemperature(); //membaca suhu dalam celsius
float f = dht.readTemperature(true); // Membaca suhu dalam satuan Fahrenheit
if (isnan(h) || isnan(t) ) {
Serial.println("Gagal Baca"); //menampilkan peringkatan bila sensor tidak terbaca
return;
}
{
UpdateLCDDisplay();
lcd.setCursor(0,1);
lcd.write(3);
lcd.print(h); //MENAMPILKAN HUMIDITY
lcd.print("%");
lcd.setCursor(9,1);
lcd.write(2);
lcd.print(t); //MENAMPILKAN SUHU
lcd.print("C");
delay(100);
}
{
UpdateLCDDisplay();
lcd.setCursor(0,1);
lcd.write(4);
lcd.print(h); //MENAMPILKAN HUMIDITY
lcd.print("%");
lcd.setCursor(9,1);
lcd.write(1);
lcd.print(t); //MENAMPILKAN SUHU
lcd.print("C");
delay(100);
}
}
void UpdateLCDDisplay()
{
int iLenOfLargeText = strlen(LargeText); // Calculate lenght of string.
if (iCursor == (iLenOfLargeText - 1) ) // Reset variable for rollover effect.
{
iCursor = 0;
}
//lcd.clear();
lcd.setCursor(0,iLineNumber);
if(iCursor < iLenOfLargeText - 16) // This loop exicuted for normal 16 characters.
{
for (int iChar = iCursor; iChar < iCursor + 16 ; iChar++)
{
lcd.print(LargeText[iChar]);
}
}
else
{
for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++) // This code takes care of printing charecters of current string.
{
lcd.print(LargeText[iChar]);
}
for (int iChar = 0; iChar <= 16 - (iLenOfLargeText - iCursor); iChar++) // Reamining charecter will be printed by this loop.
{
lcd.print(LargeText[iChar]);
}
}
iCursor++;
}