//Includes
#include <TFT_HX8357.h>
#include <DS3231.h>
#include <Wire.h>
#include "DHT.h"
//Defines
#define DHTPIN A0
#define DHTTYPE DHT22
//Instances
TFT_HX8357 tft = TFT_HX8357();
DHT dht(DHTPIN, DHTTYPE);
DS3231 Clock;
//Global Variables
const long interval = 60000;
unsigned long previousMillis = 0;
float temp;
float humid;
bool h12;
bool PM;
bool Century = false;
int DAW;
String DayOfWeek;
int L_Date;
int L_Month;
int L_Year;
int L_Hour;
int L_Minute;
String AmPm;
void setup()
{
dht.begin();
Wire.begin();
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
}
void loop()
{
unsigned long currentMillis = millis(); //Do stuff here every 60 seconds
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
tft.fillScreen(TFT_BLACK);
tft.setCursor(10, 10, 1);
tft.setTextColor(TFT_WHITE);
tft.setTextFont(4);
tft.setTextSize(1);
GetDay();
tft.print(DayOfWeek);
tft.print("-: ");
GetDate();
if (L_Date < 10)
tft.print("0");
tft.print(L_Date);
tft.print("-");
if (L_Month < 10)
tft.print("0");
tft.print(L_Month);
tft.print("-");
tft.println(L_Year);
GetTime();
tft.setCursor(30, 100, 7);
tft.setTextSize(2);
if (L_Hour < 10)
tft.print("0");
tft.print(L_Hour);
tft.print(":");
if (L_Minute < 10)
tft.print("0");
tft.print(L_Minute);
tft.setTextFont(6);
tft.setTextSize(2);
tft.println(AmPm);
GetTempHumid();
tft.setCursor(20, 280, 4);
tft.setTextSize(1);
tft.print("Temp: ");
tft.print(temp);
tft.print("Deg C");
tft.setCursor(260, 280, 4);
tft.print("Humidity: ");
tft.print(humid);
tft.print("%");
}
}
void GetTempHumid()
{
humid = dht.readHumidity();
temp = dht.readTemperature();
return;
}
void GetTime()
{
L_Hour = Clock.getHour(h12, PM);
L_Minute = Clock.getMinute();
if (h12)
{
if (PM)
{
AmPm = "pm";
}
else
{
AmPm = "am";
}
}
return;
}
void GetDate()
{
L_Date = Clock.getDate();
L_Month = Clock.getMonth(Century);
L_Year = Clock.getYear();
L_Year += 2000;
return;
}
void GetDay()
{
DAW = Clock.getDoW();
switch (DAW)
{
case 0:
DayOfWeek = "Sunday";
break;
case 1:
DayOfWeek = "Monday";
break;
case 2:
DayOfWeek = "Tuesday";
break;
case 3:
DayOfWeek = "Wednesday";
break;
case 4:
DayOfWeek = "Thursday";
break;
case 5:
DayOfWeek = "Friday";
break;
case 6:
DayOfWeek = "Saturday";
break;
default:
DayOfWeek = "ERROR";
break;
}
return;
}