#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
#define DHTPIN 26 // Pin where the DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define TFT_CS 15 // TFT CS pin
#define TFT_RST 4 // TFT RST pin (unused)
#define TFT_DC 2 // TFT DC pin
DHT dht(DHTPIN, DHTTYPE);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
dht.begin();
tft.begin();
tft.setRotation(1); // Adjust the rotation if needed
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(3);
tft.print("Temperature: ");
tft.print(temperature);
tft.println(" °C");
tft.print("Humidity: ");
tft.print(humidity);
tft.println(" %");
delay(1000);
}
Loading
ili9341-cap-touch
ili9341-cap-touch