#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int bot = 14;
int dhtP = 27;
bool Lig = false;
int Set = 0;
#define DHTTYPE DHT22
DHT dht(dhtP, DHTTYPE);
void setup() {
Serial.begin(115200);
pinMode(bot, INPUT);
dht.begin();
tft.begin();
tft.setRotation(0); //Sentido do Display 0=Portrait / 1=Landscape
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int botValue = digitalRead(bot);
if(botValue == true){
Lig = !Lig;
while(botValue == 1){
botValue = digitalRead(bot);
}
}
if(Lig == true){
if(Set != 1){
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 140);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println(" Iniciando... ");
delay(2000);
Set = 1;
}
if(Set == 1){
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(2, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.print("Temp: ");
tft.print(t);
tft.println("C");
tft.setCursor(2, 180);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3);
tft.print("Hum: ");
tft.print(h);
tft.println("%");
}
}
else if(Lig == false && Set == 1){
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(2, 140);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("Desligando... ");
delay(2000);
tft.fillScreen(ILI9341_BLACK);
Set = 2;
}
else{
tft.fillScreen(ILI9341_BLACK);
Set = 0;
}
}