#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include "DHT.h"
#define DHTPIN 17
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(1);
//Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0,0);
tft.setTextSize(2);
tft.setTextColor(ILI9341_RED);
tft.println("");
tft.println("");
tft.println(" DHT SENSOR");
// tft.setCursor(5, 1);
tft.setTextColor(ILI9341_WHITE);
tft.println("");
//tft.println("");
//tft.println("");
tft.println("");
tft.println("");
tft.print(" TEMP=");
tft.setTextColor(ILI9341_YELLOW);
tft.print(t);
tft.setTextColor(ILI9341_WHITE);
tft.println("");
//tft.println("");
//tft.println("");
tft.println("");
tft.println("");
tft.print(" HUM=");
tft.setTextColor(ILI9341_YELLOW);
tft.print(h);
tft.setTextColor(ILI9341_GREEN);
tft.println("");
tft.println("");
tft.println("");
tft.println(" SPI LCD");
// tft.setCursor(8, 0);
// tft.println("");
// //tft.println("");
// tft.println("");
// tft.println("");
// tft.println("");
// tft.println(" NANII");
// // //tft.setCursor(10, 0);
delay(5000);
}