#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <DHT.h>
int DHTPin = A0;
int DHTType = DHT22;
DHT dht(DHTPin, DHTType);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const uint8_t x = 4;
const uint8_t y = 4;
uint8_t pinBaris[x] = {9,8,7,6};
uint8_t pinKolom[y] = {5,4,3,2};
char keys[x][y] = {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
Keypad k = Keypad(makeKeymap(keys),pinBaris,pinKolom,x,y);
bool kesesuaianPIN = false;
String PINTersimpan = "998877";
String PINTerinput = "";
void wellcomeScreen(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hello, Bligus");
lcd.setCursor(0,1);
lcd.print("PIN:");
}
void setup() {
dht.begin();
Serial.begin(115200);
lcd.init();
lcd.backlight();
wellcomeScreen();
while (!kesesuaianPIN){
char bacaKey = k.getKey();
if (bacaKey != NO_KEY){
Serial.print(bacaKey);
if (bacaKey == 'D'){
if (PINTersimpan == PINTerinput){
kesesuaianPIN = true;
}
PINTerinput = "";
wellcomeScreen();
} else {
PINTerinput = PINTerinput + bacaKey;
lcd.setCursor(5,1);
lcd.print(PINTerinput);
}
}
} lcd.clear();
lcd.setCursor(0,1);
lcd.print("Berhasil LOGIN");
delay(1000);
}
void loop() {
lcd.clear();
float t = dht.readTemperature();
float h = dht.readHumidity();
Serial.println("suhu :" + String(t)+ "°C");
Serial.println("kelembaban :" + String(h)+ " %");
Serial.println("---------------------");
lcd.setCursor(0,0);
lcd.print("temp :" + String(t)+ "'C");
lcd.setCursor(0,1);
lcd.print("humid :" + String(h)+ " %");
delay(100);
lcd.clear();
delay(100);
}