#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <IRremote.h>

#define DHTPIN 12
#define DHTTYPE DHT22
#define DECODE_NEC

constexpr uint8_t IR_RECEIVE_PIN {2};
Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);

int val;
int command;

void DHTControl(float temperature, float humidity) {
  // Checks temperature and humidity values
  if (temperature >= 37 && humidity >= 60) {
    val = temperature;
    val = map(temperature, 37, 80, 45, 180);
    myservo.write(val);
  }
  else {
    myservo.write(0);
  }
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  myservo.attach(11);
  IrReceiver.begin(IR_RECEIVE_PIN);
  dht.begin();
  lcd.init();
  lcd.backlight();
}

void loop() {
  // put your main code here, to run repeatedly:
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Print Humidity
  lcd.setCursor(0, 0);
  lcd.print("HMD: ");
  lcd.print(humidity);
  lcd.print("%");

  // Print Temperature
  lcd.setCursor(0, 1);
  lcd.print("TMP: ");
  lcd.print(temperature);
  lcd.print("C");

  // Check IR Remote Inputs
  if (IrReceiver.decode()) {
    IrReceiver.printIRResultShort(&Serial);

    if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
      IrReceiver.printIRResultRawFormatted(&Serial, true);
    }

    if (IrReceiver.decodedIRData.protocol == NEC) {
      command = IrReceiver.decodedIRData.command, HEX;
      Serial.println(command);
    }

    // Remote Button 0
    if (command == 1) {
      val = 0;
      myservo.write(val);
    }

    // Remote Button 1
    else if (command == 48) {
      val = 20;
      myservo.write(val);
    }

    // Remote Button 2
    else if (command == 24) {
      val = 40;
      myservo.write(val);
    }

    // Remote Button 3
    else if (command == 122) {
      val = 0;
      myservo.write(val);
    }

    // Remote Button 4
    else if (command == 16) {
      val = 20;
      myservo.write(val);
    }

    // Remote Button 5
    else if (command == 56) {
      val = 40;
      myservo.write(val);
    }

    // Remote Button 6
    else if (command == 90) {
      val = 0;
      myservo.write(val);
    }

    // Remote Button 7
    else if (command == 66) {
      val = 20;
      myservo.write(val);
    }

    // Remote Button 8
    else if (command == 74) {
      val = 40;
      myservo.write(val);
    }

    // Remote Button 9
    else if (command == 82) {
      val = 40;
      myservo.write(val);
    }

    else {
      DHTControl(temperature, humidity);
    }

    IrReceiver.resume();
    return val;
  }
  delay(1000);
  lcd.clear();
}
$abcdeabcde151015202530354045505560fghijfghij