/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-door-sensor
*/
#include <Arduino_GFX_Library.h>
#include <WiFi.h>
#include "time.h"
#include "sntp.h"
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer1 = "pool.ntp.org";
const char* ntpServer2 = "time.nist.gov";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;
const char* time_zone = "CET-1CEST,M3.5.0,M10.5.0/3"; // TimeZone rule for Europe/Rome including daylight adjustment rules (optional)
// int doorState;
// #define DOOR_SENSOR_PIN 13 // ESP32 pin GPIO19 connected to door sensor's pin
// Set these to your desired credentials.
#define TFT_SCK 18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CS 22
#define TFT_DC 21
#define TFT_RESET 17
Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
Arduino_ILI9341 display = Arduino_ILI9341(&bus, TFT_RESET);
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("No time available (yet)");
return;
}
display.setTextColor(WHITE, RED);
display.setTextSize(2);
display.setCursor(180, 5);
display.print(&timeinfo, "%H:%M");
}
// Callback function (get's called when time adjusts via NTP)
void timeavailable(struct timeval *t)
{
Serial.println("Got time adjustment from NTP!");
printLocalTime();
}
void setup()
{
Serial.begin(9600);
// set notification call-back function
sntp_set_time_sync_notification_cb( timeavailable );
/**
* NTP server address could be aquired via DHCP,
*
* NOTE: This call should be made BEFORE esp32 aquires IP address via DHCP,
* otherwise SNTP option 42 would be rejected by default.
* NOTE: configTime() function call if made AFTER DHCP-client run
* will OVERRIDE aquired NTP server address
*/
sntp_servermode_dhcp(1); // (optional)
/**
* This will set configured ntp servers and constant TimeZone/daylightOffset
* should be OK if your time zone does not need to adjust daylightOffset twice a year,
* in such a case time adjustment won't be handled automagicaly.
*/
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer1, ntpServer2);
/**
* A more convenient approach to handle TimeZones with daylightOffset
* would be to specify a environmnet variable with TimeZone definition including daylight adjustmnet rules.
* A list of rules for your zone could be obtained from https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
*/
//configTzTime(time_zone, ntpServer1, ntpServer2);
//connect to WiFi
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
display.begin();
display.fillScreen(BLACK);
display.setCursor(20, 20);
display.setTextSize(6);
display.fillRect(0, 0, 240, 80, RED);
display.setTextColor(WHITE);
display.print("NetDsk");
display.setTextSize(2);
display.setCursor(20, 150);
display.print("V.1.0");
display.setCursor(20, 170);
display.print("Tim Thielemann");
delay(5000);
display.fillScreen(BLACK);
display.setCursor(20, 5);
display.setTextSize(2);
display.fillRect(0, 0, 240, 50, RED);
display.setTextColor(WHITE);
display.print("NetDsk");
display.setCursor(20, 25);
display.print("Hauptmenu");
display.setCursor(20, 100);
display.print("1. Fahrzeug DIAG");
display.setCursor(20, 120);
display.print("2. Fahrzeug INFO");
display.setCursor(20, 120);
display.fillRect(2, 260, 58, 58, RED);
display.fillRect(64, 260, 58, 58, RED);
display.fillRect(126, 260, 58, 58, RED);
display.fillRect(188, 260, 58, 58, RED);
}
void loop() {
printLocalTime();
// doorState = digitalRead(DOOR_SENSOR_PIN); // read state
//
// if (doorState == HIGH) {
// Serial.println("The door is open");
// } else {
// Serial.println("The door is closed");
// }
}Loading
ili9341-cap-touch
ili9341-cap-touch