/**
* Copyright(C), 2016-2038, KenRobot.com
* FileName: dht.ino
* Author: 啃萝卜
* Create: 2017/11/25
* Modify: 2017/11/25
*/
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
int button_0 = 11;
DHT hts221_0(8, DHT22);
LiquidCrystal_I2C lcd_0(0x27, 16, 2);
void setup() {
pinMode(button_0, INPUT);
hts221_0.begin();
lcd_0.begin();
lcd_0.clear();
Serial.begin(9600);
lcd_0.noBacklight();
}
void loop() {
if (Serial.available()) {
for (int i = 0; i < 6; i++) {
Serial.println(Serial.read());
Serial.println(hts221_0.readTemperature());
Serial.println(hts221_0.readHumidity());
delay(1000);
}
}
if (digitalRead(11) == 1) {
delay(200);
lcd_0.backlight();
for (int i = 0; i < 6; i++) {
lcd_0.clear();
lcd_0.print(hts221_0.readTemperature());
lcd_0.print(hts221_0.readHumidity());
lcd_0.setCursor(15, 1);
lcd_0.print("^c");
lcd_0.setCursor(15, 2);
lcd_0.print("%H");
lcd_0.setCursor(13, 1);
lcd_0.print(hts221_0.readTemperature());
lcd_0.setCursor(13, 2);
lcd_0.print(hts221_0.readHumidity());
delay(1000);
}
delay(10000);
}
}
|