/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
#define DHTPIN 6
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define GRAY 0xDEFB
void setup() {
tft.begin();
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
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);
tft.setRotation(1);
tft.drawLine(0, 50, 320, 50, WHITE); //Draw first horizontal line
tft.drawLine(106, 240, 106, 50, WHITE); //Draw fourth vertical line
tft.drawLine(212, 240, 212, 50, WHITE); //Draw fourth vertical line
tft.drawLine(0, 145, 320, 145, WHITE); //Draw first horizontal line
tft.setRotation(1);
tft.fillRect(0,5, 300, 30, ILI9341_RED);
tft.drawRect(0,5,300,30,ILI9341_BLACK);
tft.setCursor(20,10);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Develop by Janta Group");
tft.setRotation(1);
tft.setCursor(0, 60);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.print("Temp ");
tft.setCursor(0, 90);
tft.print(t);
tft.print(" ");
tft.print("*C");
tft.setRotation(1);
tft.setCursor(112,60);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Humidity ");
tft.setCursor(112,90);
tft.print(h);
tft.print(" ");
tft.print("%");
}