#include "DHT.h"
#define DHTPIN 2 
#define DHTTYPE DHT22 
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"

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

void setup() {
  Serial.begin(9600);
  dht.begin();
  lcd.init();
  lcd.backlight();
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print("Humidity : ");
  Serial.print(h);
  Serial.println("%");
  Serial.print("Temp : ");
  Serial.print(t);
  Serial.println("°C");
  lcd.setCursor(0,0);
  lcd.print("Temp    : " + String(t) + " C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: "+ String(h)+"%");
  lcd.setCursor(0,2);
  DateTime now = rtc.now();
  lcd.print(now.year(), DEC);
  lcd.print('/');
  // if((now.month()) < 10){
  //   lcd.print('0');
  // }
  lcd.print(now.month(), DEC);
  lcd.print('/');
  lcd.print(now.day(), DEC);
  lcd.print(" ");
  lcd.print(now.hour(), DEC);
  lcd.print(':');
  if((now.minute()) < 10){
    lcd.print('0');
  }
  lcd.print(now.minute(), DEC);
  lcd.print(':');
  if((now.second()) < 10){
    lcd.print('0');
  }
  lcd.print(now.second(), DEC);
  lcd.println();
}
GND5VSDASCLSQWRTCDS1307+