#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define DHT_PIN1 12 // Pin for the first DHT sensor
#define DHT_PIN2 13 // Pin for the second DHT sensor
#define DHT_TYPE DHT22
DHT dht1(DHT_PIN1, DHT_TYPE);
DHT dht2(DHT_PIN2, DHT_TYPE);
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
dht1.begin();
dht2.begin();
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
tft.setCursor(0, 0);
float temperature1 = dht1.readTemperature();
float humidity1 = dht1.readHumidity();
float temperature2 = dht2.readTemperature();
float humidity2 = dht2.readHumidity();
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(3);
tft.println("Suhu & Kelembaban");
tft.println("");
if(temperature1 < 40){
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Suhu 1: ");
tft.print(temperature1,1);
tft.println(" C ");
tft.println("");
tft.print("Kel 1: ");
tft.print(humidity1,1);
tft.println(" % ");
tft.println("");
}
else{
tft.setTextColor(ILI9341_RED,ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Suhu 1: ");
tft.print(temperature1,1);
tft.println(" C ");
tft.println("");
tft.print("Kel 1: ");
tft.print(humidity1,1);
tft.println(" % ");
tft.println("");
}
if(temperature2 < 40){
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Suhu 2: ");
tft.print(temperature2,1);
tft.println(" C ");
tft.println("");
tft.print("Kel 2: ");
tft.print(humidity2,1);
tft.println(" % ");
tft.println("");
}
else{
tft.setTextColor(ILI9341_RED,ILI9341_BLACK);
tft.setTextSize(3);
tft.print("Suhu 2: ");
tft.print(temperature2,1);
tft.println(" C ");
tft.println("");
tft.print("Kel 2: ");
tft.print(humidity2,1);
tft.println(" % ");
tft.println("");
}
}