#include <DHTesp.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define Ledkuning 27
#define Ledbiru 26
#define Ledmerah 14
#define DHTPIN 15
int buzzer = 25;

const int DHT_PIN = 15;
DHTesp dhtSensor;

Adafruit_SSD1306 display(128, 64, &Wire, -1);


void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(Ledkuning, OUTPUT);
  pinMode(Ledbiru, OUTPUT);
  pinMode(Ledmerah, OUTPUT);
  Serial.begin(9600); 
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(1);
  display.setTextSize(1);
  display.display();
  
}

void loop() {
 float temp = dhtSensor.getTemperature();

 display.clearDisplay();
 display.setCursor(25,10);
 display.print("Suhu: ");
 display.print(temp);
 display.print("  C");

 if(temp<29){
   digitalWrite(Ledkuning, LOW);
   digitalWrite(Ledmerah, LOW);
   digitalWrite(Ledbiru, HIGH);
   display.setCursor(7,30);
   display.print("Suhu Terlalu dingin");

 }
 else if(temp>29 && temp <=35){
   digitalWrite(Ledkuning, HIGH);
   digitalWrite(Ledmerah, LOW);
   digitalWrite(Ledbiru, LOW);
   display.setCursor(30,30);
   display.print("Suhu Normal");
 }
 else{
   digitalWrite(Ledkuning, LOW);
   digitalWrite(Ledmerah, HIGH);
   digitalWrite(Ledbiru, LOW);
   display.setCursor(9,30);
   display.print("Suhu Terlalu Panas");

   tone(buzzer, 800, 300);
   delay(300);
   tone(buzzer, 1600, 300);
   delay(300);
   

 }

display.display();

}