// --------------------------------------------------------------------------------
/*

17 溫度濕度監測器

[學習重點]

1. 認識 DHT11, DHT22

[挑戰]

- 自製 IoT 溫度濕度監測器
https://jasonworkshop.com/b20211001

Created by Jason on 17 Aug 2022.

*/
// --------------------------------------------------------------------------------

// LCD
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

// DHT
#include "DHT.h"
#define DHTPIN A3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // LCD
  lcd.init();
  lcd.backlight();

  // DHT
  dht.begin();
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // 顯示文字訊息到 LCD
  lcd.setCursor(1,1); // 設定遊標位置 (左邊數第幾個字, 行數)
  lcd.print("Temperature: ");
  lcd.print(t);
  lcd.setCursor(1,2);
  lcd.print("Humidity: ");
  lcd.print(h);

  delay(100);
}