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

#define LEBAR_LAYAR 128 // Lebar layar OLED yang digunakan
#define TINGGI_LAYAR 64 // Tinggi layar OLED yang digunakan

Adafruit_SSD1306 oled(LEBAR_LAYAR, TINGGI_LAYAR, &Wire, -1);

const int DHT_PIN = 15;
DHTesp dhtSensor;

void sendSensor()
{
 TempAndHumidity  data = dhtSensor.getTempAndHumidity();
 Serial.println("Temp: " + String(data.temperature, 2) + "°C");
 Serial.println("---");
 
}


void setup() {
  Serial.begin(9600);
  
  TempAndHumidity  data = dhtSensor.getTempAndHumidity();
  Serial.println("Temp: " + String(data.temperature, 2) + "°C");
  Serial.println("---");

  // initialize OLED display with I2C address 0x3C
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("failed to start SSD1306 OLED"));
    while (1);
  }

  delay(2000);         
  oled.clearDisplay(); // clear display

  oled.setTextSize(1);         // Atur ukuran text
  oled.setTextColor(WHITE);    // Atur warna text
  oled.setCursor(0, 10);       // Atur posisi text pada display
  if(digitalRead(data.temperature) < 29){
    digitalWrite(19, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(18, LOW);
    oled.println("Suhu Rendah");
    
  }if else(digitalRead(data.temperature) <35 ){
    digitalWrite(5, HIGH);
    digitalWrite(18, LOW);
    digitalWrite(19, LOW);
    oled.println("Suhu Panas");
  }else{
    digitalWrite(18, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(19, LOW);
    oled.println("Suhu Cukup");

  }
  
  oled.display();              // menampilkan display OLED
}