#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.h> // Hardware-specific library
#include <Wire.h> // For I2C communication
#include <RTClib.h> // Real-time clock library
// Pin definitions for TFT
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
// Pin definitions for RTC
#define RTC_SDA 12
#define RTC_SCL 13
// Create display and RTC objects
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK);
RTC_DS3231 rtc; // Use RTC_DS3231
void setup() {
Serial.begin(115200);
// Initialize the TFT screen
tft.begin();
tft.setRotation(3); // Rotate display if needed
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
// Initialize the RTC
Wire.begin(RTC_SDA, RTC_SCL); // Use the defined SDA and SCL pins
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
Serial.println("RTC initialized");
// Uncomment this line if you want to set the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = rtc.now();
// Print debug information to the Serial Monitor
Serial.print("Current Time: ");
Serial.print(now.hour());
Serial.print(':');
if (now.minute() < 10) Serial.print('0');
Serial.print(now.minute());
Serial.print(':');
if (now.second() < 10) Serial.print('0');
Serial.print(now.second());
Serial.println();
// Clear the screen
//tft.fillScreen(ILI9341_BLACK);
// Display the current time on the TFT
tft.setCursor(10, 10);
tft.print("Time: ");
tft.print(now.hour());
tft.print(':');
if (now.minute() < 10) tft.print('0');
tft.print(now.minute());
tft.print(':');
if (now.second() < 10) tft.print('0');
tft.print(now.second());
delay(1000); // Update every second
}
Loading
ili9341-cap-touch
ili9341-cap-touch