#include <DHT.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Wire.h>

#define ledHijau 7
#define ledKuning 8
#define ledMerah 9

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

DHT dht(2, DHT22);

void setup() {

pinMode(ledHijau, OUTPUT);
pinMode(ledKuning, OUTPUT);
pinMode(ledMerah, OUTPUT);

display.begin(SSD1306_SWITCHCAPVCC,0x3C);
display.setTextColor(1);
display.setTextSize(1);
display.display();

Serial.begin(115200);
dht.begin();

}

void loop() {

delay(2000);
display.clearDisplay();

float humi = dht.readHumidity();
float temp = dht.readTemperature();
display.clearDisplay();
display.setTextSize(1);             
display.setTextColor(WHITE);        
display.setCursor(10,0);             
display.println("=SMS KANDANG IoT=");
display.setCursor(0,12);             
display.println("Temperature: ");
display.print(temp);
display.print(" C");
display.setCursor(0,32);             
display.println("Humidity: ");
display.print(humi);
display.print(" %");
display.display();
delay(1000);

if(temp <29){

  digitalWrite(ledHijau, HIGH);
  digitalWrite(ledKuning, LOW);
  digitalWrite(ledMerah, LOW);

    display.setCursor(40,50);             
    display.println("SUHU DINGIN");
    display.display();

}
else if(temp > 29 && temp <=35){
  digitalWrite(ledHijau, LOW);
  digitalWrite(ledKuning, HIGH);
  digitalWrite(ledMerah, LOW);

  display.clearDisplay();
  display.setCursor(40,50);             
  display.println("SUHU CUKUP");
  display.display();
}
else if(temp > 35){
  digitalWrite(ledHijau, LOW);
  digitalWrite(ledKuning, LOW);
  digitalWrite(ledMerah, HIGH);

    display.setCursor(40,50);             
    display.println("SUHU PANAS");
}
  Serial.print("Kelembaban: ");
  Serial.println(humi);
  Serial.print("Suhu:       ");
  Serial.println(temp);
  delay(500);

}