#include <Keypad.h> // Biblioteca do codigo
#include "DHT.h"
#define DHTTYPE DHT22 //DHT22 (AM2302), AM2321
uint8_t DHTPin = 14;
DHT dht(DHTPin, DHTTYPE);
const byte LINHAS = 4; // Linhas do teclado
const byte COLUNAS = 4; // Colunas do teclado
const char TECLAS_MATRIZ[LINHAS][COLUNAS] = { // Matriz de caracteres (mapeamento do teclado)
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
const byte PINOS_LINHAS[LINHAS] = {9, 8, 7, 6}; // Pinos de conexao com as linhas do teclado
const byte PINOS_COLUNAS[COLUNAS] = {5, 4, 3, 2}; // Pinos de conexao com as colunas do teclado
Keypad teclado_personalizado = Keypad(makeKeymap(TECLAS_MATRIZ), PINOS_LINHAS, PINOS_COLUNAS, LINHAS, COLUNAS); // Inicia teclado
float temperatura;
float umidade;
void setup()
{
Serial.begin(115200);
Serial.begin(9600); // Inicia porta serial
delay(100);
pinMode(DHTPin, INPUT);
dht.begin();
}
void loop(){
sensorDHT22();
delay(1000);
}
void sensorDHT22(){
temperatura = dht.readTemperature(); // Obtem os valores da temperatura
umidade = dht.readHumidity(); // Obtem os valores da umidade
Serial.print("Temepratura=");
Serial.println(temperatura);
Serial.print("umidade=");
Serial.println(umidade);
}
void setup() {
}
void loop() {
char leitura_teclas = teclado_personalizado.getKey(); // Atribui a variavel a leitura do teclado
if (leitura_teclas) { // Se alguma tecla foi pressionada
Serial.println(leitura_teclas); // Imprime a tecla pressionada na porta serial
}
}