capteur DHT+clavier+écran

clement64
mar, 07/05/2016 - 17:39
Bonjour, je souhaite configurer mon arduino uno pour que lorsque je tape la touche 1, l'écran m'affiche le pourcentage d'humidité et lorsque j'appuie sur la touche 2, celui ci m'affiche la température. J'utilise un capteur DHT11 et un écran 16x2.
Voici mon problème : que je tape la touche 1 ou 2, l'écran ne m'affiche que la température..
Voici le code :
#include <dht.h>
#define dht_apin A0
dht DHT;
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
int n = 1;
LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
lcd.begin (16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
}
void loop(){
DHT.read11(dht_apin);
char key = keypad.getKey();
if (key != NO_KEY){
if (key=='1')
lcd.clear();
lcd.print("humidite=");
lcd.print(DHT.humidity);
if (key=='2')
lcd.clear();
lcd.setCursor(0,0);
lcd.print("temperature=");
lcd.print(DHT.temperature);
lcd.println("C ");
if (key=='*') lcd.clear();
}
}
Merci d'avance