#include <SPI.h>
#include "Ucglib.h"
#include <RTClib.h>
RTC_DS3231 rtc;
// Define the pins for the ILI9486 TFT display
Ucglib_ILI9486_18x320x480_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9, /*cs=*/ 10, /*reset=*/ 8);
void setup() {
// Initialize communication with the TFT display
ucg.begin(UCG_FONT_MODE_SOLID);
// Set rotation of the display (optional, adjust as needed)
// ucg.setRotate(90);
// Clear the screen
ucg.clearScreen();
// Initialize the RTC
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Check if the RTC lost power and if so, set the time
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void displayCurrentTime() {
DateTime now = rtc.now();
// Set text color to yellow
ucg.setColor(255, 255, 255);
// Set font size for big digits
ucg.setFontMode(UCG_FONT_MODE_TRANSPARENT);
ucg.setFont(ucg_font_helvR24_tr);
// Print the current time with double-sized digits
int xPos = 30; // Adjust the X position as needed
int yPos = 100; // Adjust the Y position as needed
int fontSize = 3; // Double-sized digits
// Print the current time
ucg.setPrintPos(60, 100);
ucg.print(now.hour(), DEC);
ucg.print(":");
ucg.print(now.minute(), DEC);
ucg.print(":");
ucg.print(now.second(), DEC);
}
void ucglib_graphics_test(void) {
// Set background gradient colors
ucg.setColor(0, 0, 40, 80);
ucg.setColor(1, 80, 0, 40);
ucg.setColor(2, 255, 0, 255);
ucg.setColor(3, 0, 255, 255);
// Draw a gradient box
ucg.drawGradientBox(0, 0, ucg.getWidth(), ucg.getHeight());
// Set text color
ucg.setColor(255, 0, 0);
// Print text on the screen
ucg.setColor(255, 160, 0);
ucg.setPrintDir(0);
ucg.setPrintPos(2, 50);
ucg.setColor(55, 160, 0);
ucg.print("Ucglib");
ucg.setColor(255, 255, 255);
ucg.setPrintPos(2, 150 + 20);
ucg.print("GraphicsTest");
// Set text color to yellow
ucg.setColor(255, 2500, 250);
ucg.setPrintPos(20, 50);
// ucg.print("Ucglib");
ucg.setPrintPos(2, 250 + 20);
ucg.print("code by ARVIND");
}
void loop() {
// Run the graphics test function
ucglib_graphics_test();
// Display the current time
displayCurrentTime();
// Delay for 5 seconds before restarting
delay(5000);
// Clear the screen for the next iteration
ucg.clearScreen();
}