/*Latihan Pertemuan Ke-4 BootCamp Batch - 5
  esp32 + DHT22 + LED RGB Kondisi :
  
  • Jika Suhu > 50  Lampu berwarna Merah.
  • Jika Suhu > 30 s/d 50  Lampu berwarna Kuning
  • Jika Suhu < 30   Lampu berwarna Hijau
  
  Nama  : Vonny Wendry F.
*/

#include <DHTesp.h>;

#define DHTPIN 15
const int PINRED = 18; // merah 255, 0, 0 => suhu > 50
const int PINBLU = 19; // Kuning 0,255, 255 => suhu > 30 s/d 50
const int PINGRN = 21; // Hijau   245, 0,152 => suhu < 30
const float merah = 50.00;
const float Kuning = 30.00;
 


DHTesp dht;

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

  dht.setup(DHTPIN, DHTesp::DHT22);

  pinMode(PINRED, OUTPUT);
  pinMode(PINGRN, OUTPUT);
  pinMode(PINBLU, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  TempAndHumidity data = dht.getTempAndHumidity();
  
  //extrak
  float temp = data.temperature;
   //extrak
  float hum = data.temperature;
 Serial.println(" Suhu Saat ini   " + String(temp,2));
 
  
 
  if(temp > merah ){
     Serial.println(" Suhu Saat ini Merah  " + String(temp,2));
    analogWrite(PINRED,0);
    analogWrite(PINGRN,200);
    analogWrite(PINBLU,255);
    delay(1000); // this speeds up the simulation
  }else if(temp > Kuning ){ //0,255, 255 
    Serial.println(" Suhu Saat ini Kuning  " + String(temp,2));
    analogWrite(PINRED,0);
    analogWrite(PINGRN,100);
    analogWrite(PINBLU,205);
    delay(1000); // this speeds up the simulation
  }else{
    Serial.println(" Suhu Saat ini Normal  " + String(temp,2));
     analogWrite(PINRED,255);
    analogWrite(PINGRN,0);
    analogWrite(PINBLU,255);
    delay(1000); // this speeds up the simulation
  
  }

  delay(2000); // this speeds up the simulation


}