#include <DHT.h>
DHT dht(27, DHT22);

int ledR = 19;
int ledB = 2;
int ledG = 17;

int pinbuz = 18;
int chanbuz = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  dht.begin();
  pinMode(ledR, OUTPUT);
  pinMode(ledB, OUTPUT);
  pinMode(ledG, OUTPUT);

  ledcAttachPin(pinbuz, chanbuz);
}

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

  Serial.print("Suhu : ");
  Serial.println(temp);
  Serial.println();
  delay(100); // this speeds up the simulation

  if (temp > 40 || temp < 10){
    digitalWrite(ledR, HIGH);
    digitalWrite(ledB, HIGH);
    digitalWrite(ledB, LOW);

    ledcWriteTone(chanbuz, 2000);

  }else if (temp > 35) {
    digitalWrite(ledR, HIGH);
    digitalWrite(ledB, LOW);
    digitalWrite(ledG, LOW);
    
    ledcWriteTone(chanbuz, 0);

  }else if (temp >= 15 && temp <= 35){
    digitalWrite(ledR, LOW);
    digitalWrite(ledB, LOW);
    digitalWrite(ledG, HIGH);

    ledcWriteTone(chanbuz, 0);

  }else if(temp < 15){
    digitalWrite(ledR, LOW);
    digitalWrite(ledB, HIGH);
    digitalWrite(ledG, LOW);

    ledcWriteTone(chanbuz, 1000);
  }
}