#include "RTClib.h"
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define TFT_DC 9
#define TFT_CS 10
#define DHTPIN 2
#define DHTTYPE DHT22
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
dht.begin();
tft.begin();
tft.setRotation(1);
tft.setCursor(0 ,1);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3,4);
tft.println("teplota");
tft.setCursor(165 ,1);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3,4);
tft.println("vlhkost");
tft.drawLine(0,85, 300,85, ILI9341_WHITE);
tft.setCursor(50 ,110);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(3,4);
tft.println("cas a datum");
}
void loop() {
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
tft.setRotation(1);
int i;
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print("% Temperature: ");
Serial.print(t);
Serial.println("°C ");
Serial.print("Time: ");
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setTextSize(3);
tft.setCursor(20,50);
tft.print(t,1);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setTextSize(3);
tft.setCursor(185,50);
tft.print(h,1);
tft.print("%");
delay(1000);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.setTextSize(3);
tft.setCursor(106,150);
tft.print(now.hour(), DEC);
tft.print(':');
tft.print(now.minute(), DEC);
}