/*************************************************
*     AUTOMATED TEMPERATURE CONTROLLLER USING    *
*           ESP32 MICROCONTROLLER                *
*        SUBMITTED BY: PAULO R. BENDIJO          *
*     SUBMITTED TO: PROF. MICHAEL T. SAMONTE     *
**************************************************/
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 23
#define DHTTYPE DHT22
#define GREEN_LED 19
#define RED_LED 5
#define BUZZ1 2

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup() {
  lcd.init();
  lcd.backlight();
  dht.begin();
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(BUZZ1, OUTPUT);
}

void loop() {
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();

  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temp);
  lcd.print("C");

  lcd.setCursor(0, 1); 
  lcd.print("Humidity: ");
  lcd.print(hum);
  lcd.print("%");

  lcd.setCursor(0, 2);
  lcd.print("Created by:");
  lcd.setCursor(0, 3);
  lcd.print("Paulo R. Bendijo");

  if (temp <= 28) {
    digitalWrite(BUZZ1, HIGH);
    digitalWrite(GREEN_LED, LOW);
    digitalWrite(RED_LED, HIGH);
  } else {
    digitalWrite(BUZZ1, LOW);
    digitalWrite(GREEN_LED, HIGH);
    digitalWrite(RED_LED, LOW);
  }
  delay(2000);
}