#include <DHT.h>
#include <LiquidCrystal_I2C.h>;
#include <Wire.h>
#include <Keypad.h>
#define DHTPIN 13
#define DHTTYPE DHT22
int totalColumns = 20;
int totalRows = 4;
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, totalColumns, totalRows);
// define DHT infomation
DHT dht(DHTPIN, DHTTYPE);
// Define Keypad 4x4 information
const uint8_t ROWS = 4; /* four rows */
const uint8_t COLS = 4; /* four columns */
/* define the symbols on the buttons of the keypads */
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = {19, 18, 17, 16}; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = {35, 34, 33, 32}; // Pins connected to R1, R2, R3, R4
/* initialize an instance of class NewKeypad */
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
float _temp, _humi;
void setup() {
Serial.begin(115200);
// initialize LCD
LCD.init();
// turn on LCD backlight
LCD.backlight();
dht.begin();
}
void loop() {
// Read Humidity
float _humi = dht.readHumidity();
// Read temperature
float _temp = dht.readTemperature();
// // Check if any reads failed and exit early (to try again).
// if (isnan(_humi) || isnan(_temp))
// {
// LCD.println("Failed to read from DHT sensor!");
// }
// else
// {
// // set cursor to first column, first row
// LCD.setCursor(0, 0);
// LCD.print("Temperature: ");
//// LCD.print(_temp);
// LCD.print("35");
// LCD.print("C");
//
// LCD.setCursor(0, 1);
// LCD.print("Humidity: ");
//// LCD.print(_humi);
// LCD.print("70");
// LCD.print("%");
// delay(1000);
// }
char key = keypad.getKey();
if (key) {
Serial.println(key);
}
}