#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_system.h"
#include "sdkconfig.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "U8g2_for_Adafruit_GFX.h"
#include "ESP32Time.h"
#include "Dialog_plain_20.h"
#include "Calligraffitti_Regular_20.h"
// SPI configuration
#define TFT_MOSI 11
#define TFT_MISO 13
#define TFT_CLK 12
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
ESP32Time rtc(3600);
char houreChar[3];
char mintChar[4];
char secondChar[3];
char dateChar[20];
char dayChar[10];
// Initialize with an empty string
char prevhoureChar[3] = "";
char prevmintChar[4] = "";
char prevsecondChar[3] = "";
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
void printText(const char* text, uint16_t color, int x, int y, int textSize);
void printText1(const char* text, uint16_t color, int x, int y, int textSize);
void getTimeTask(void *pvParameters) {
while (1) {
String houreStr = rtc.getTime("%H");
String mintStr = rtc.getTime(":%M");
String secondStr = rtc.getTime("%S");
String dateStr = rtc.getTime("%d %B %Y");
String dayStr = rtc.getTime("%A");
houreStr.toCharArray(houreChar, 3);
mintStr.toCharArray(mintChar, 4);
secondStr.toCharArray(secondChar, 3);
dateStr.toCharArray(dateChar, 20);
dayStr.toCharArray(dayChar, 10);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void displayTimeTask(void *pvParameters) {
// Initialize SPI bus
spi_bus_config_t buscfg = {
.mosi_io_num = TFT_MOSI,
.miso_io_num = TFT_MISO,
.sclk_io_num = TFT_CLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 16 * 320 * 2 + 8
};
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, SPI_DMA_CH_AUTO));
// Initialize ILI9341 display
tft.begin();
u8g2_for_adafruit_gfx.begin(tft);
tft.setRotation(1); // Set rotation
tft.fillScreen(ILI9341_WHITE);
printText(prevhoureChar, ILI9341_WHITE, 60, 50, 5);
vTaskDelay(500 / portTICK_PERIOD_MS);
printText1("IXLens", ILI9341_BLACK, 110, 110, 2);
vTaskDelay(2000 / portTICK_PERIOD_MS);
printText1("IXLens", ILI9341_WHITE, 110, 110, 2);
printText("PM", ILI9341_BLACK, 260, 110, 2);
printText("IXLens", ILI9341_BLACK, 110, 20, 1);
printText("68 F", ILI9341_BLACK, 10, 220, 1);
rtc.setTime(30, 2, 15, 6, 7, 2024); // Set initial time
while (1) {
if (strcmp(houreChar, prevhoureChar) != 0) {
printText(prevhoureChar, ILI9341_WHITE, 20, 110, 3);
strcpy(prevhoureChar, houreChar);
printText(houreChar, ILI9341_BLACK, 20, 110, 3);
}
if (strcmp(mintChar, prevmintChar) != 0) {
printText(prevmintChar, ILI9341_WHITE, 90, 110, 3);
strcpy(prevmintChar, mintChar);
printText(mintChar, ILI9341_BLACK, 90, 110, 3);
}
if (strcmp(secondChar, prevsecondChar) != 0) {
printText(prevsecondChar, ILI9341_WHITE, 200, 130, 2);
strcpy(prevsecondChar, secondChar);
printText(secondChar, ILI9341_BLACK, 200, 130, 2);
}
printText(dayChar, ILI9341_BLACK, 70, 180, 2);
printText(dateChar, ILI9341_BLACK, 90, 220, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main() {
xTaskCreate(getTimeTask, "getTimeTask", 2048, NULL, 5, NULL);
xTaskCreate(displayTimeTask, "displayTimeTask", 4096, NULL, 5, NULL);
}
void printText(const char* text, uint16_t color, int x, int y, int textSize) {
tft.setCursor(x, y);
u8g2_for_adafruit_gfx.setFont(u8g2_font_ncenB14_tr); // Example font, change to your font
tft.setTextColor(color);
tft.setTextSize(textSize);
tft.setTextWrap(true);
tft.print(text);
}
void printText1(const char* text, uint16_t color, int x, int y, int textSize) {
tft.setCursor(x, y);
u8g2_for_adafruit_gfx.setFont(u8g2_font_courB08_tr); // Example font, change to your font
tft.setTextColor(color);
tft.setTextSize(textSize);
tft.setTextWrap(true);
tft.print(text);
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1