#include <dht.h>
// address:0x27,2 rows 16 columns
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void displaySetup(){
lcd.init();
lcd.backlight();
lcd.setCursor(0,1); //col 0, row 1
//lcd.print("Arduino ");
}
#define DHT11_PIN 4
dht DHT;
int secondCounter=0;
void setup(){
displaySetup();
Serial.begin(9600);
lcd.setCursor(0,0); //col 0, row 0
lcd.print("Welcome!");
delay(1000);
lcd.setCursor(0,1); //col 0, row 1
lcd.print("I'm an IoT toy!");
delay(1000);
lcd.clear();
}
void loop(){
int chk;
chk = DHT.read(DHT11_PIN);
if(chk== DHTLIB_OK){
Serial.print(DHT.humidity,1); //小数位数
Serial.print(",\t");
Serial.println(DHT.temperature,1);
lcd.setCursor(0,0); //col 0, row 0
lcd.print("Temp :");
lcd.print(DHT.temperature);
lcd.setCursor(0,1); //col 0, row 1
lcd.print("Humid:");
lcd.print(DHT.humidity);
}
lcd.setCursor(13,1);
lcd.print(secondCounter%2==0? "*" : " ");
secondCounter++;
delay(1000);
}