// STM32 Nucleo-C031C6 SPI LCD Example
// Simulation: https://wokwi.com/projects/365549388158011393
#include <WiFi.h>
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <DHT.h>
#define TFT_DC 2
#define TFT_CS 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define BEEPER_PIN 5
#define DHTPIN 0
#define NTP_SERVER "asia.pool.ntp.org"
#define UTC_OFFSET 28800
#define UTC_OFFSET_DST 0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
tft.setCursor(15, 1);
tft.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
tft.setCursor(0, 10);
//tft.println("Connection Err");
return;
}
tft.setCursor(0, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3.8);
tft.println(&timeinfo, "%I:%M:%S %p");
tft.setCursor(0, 80);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println(&timeinfo, "%d/%m/%Y");
tft.setCursor(60, 115);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.println(&timeinfo, "%A "); // Print the day of the week
}
void setup() {
Serial.begin(115200);
pinMode(BEEPER_PIN, OUTPUT);
dht.begin(); // Start the DHT sensor
tft.setCursor(0, 0);
tft.print("Connecting to ");
tft.setCursor(0, 1);
tft.print("WiFi ");
tft.begin();
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(2.7);
tft.setCursor(1, 10);
tft.println("Philippine Time");
//tft.setCursor(0, 60);
//tft.println("Updating time...");
//Created by:
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setCursor(1, 300);
tft.println("Lhon's WIFI Clock");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(2);
tft.setCursor(0, 170);
tft.println("Temperature");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.setCursor(140, 170);
tft.println("Humidity");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
printLocalTime();
float h = dht.readHumidity();
float t = dht.readTemperature();
//LCD.setCursor(0, 3);
//tft.setTextColor(ILI9341_GREEN);
//tft.setTextSize(4);
//LCD.println("Temp:");
int temperatureWhole = static_cast<int>(t);
int humidWhole = static_cast<int>(h);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(4);
tft.setCursor(20, 195);
tft.println(temperatureWhole);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(4);
tft.setCursor(75, 195);
tft.println("C");
tft.setCursor(140, 195);
tft.println(humidWhole);
tft.setCursor(200, 195);
tft.println("%");
delay(10);
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return;
}
}