#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pin definitions for the ILI9341
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
// Create an instance of the ILI9341 display driver
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
const int clockRadius = 100;
const int centerX = 120;
const int centerY = 120;
const int secondHandLength = clockRadius - 10;
const int minuteHandLength = clockRadius - 20;
const int hourHandLength = clockRadius - 30;
const int handThickness = 3; // Increase thickness for the hour and minute hands
void setup() {
// Initialize the display
tft.begin();
// Set the rotation of the display for vertical orientation
tft.setRotation(0); // Adjust if necessary
// Draw the static clock display
drawClock();
}
void loop() {
// If you want to update the time, you will need to add that code here.
}
void drawClock() {
// Clear the screen with a black background
tft.fillScreen(ILI9341_BLACK);
// Draw the clock face with a blue circle
int centerX = 120, centerY = 130; // Center of the clock face for vertical orientation
int radius = 100; // Radius of the clock face
tft.drawCircle(centerX, centerY, radius, ILI9341_BLUE);
// Draw the hour markers
for (int i = 0; i < 12; i++) {
float angle = i * 30;
float sx = cos(angle * DEG_TO_RAD) * (radius - 10);
float sy = sin(angle * DEG_TO_RAD) * (radius - 10);
float ex = cos(angle * DEG_TO_RAD) * radius;
float ey = sin(angle * DEG_TO_RAD) * radius;
tft.drawLine(centerX + sx, centerY - sy, centerX + ex, centerY - ey, ILI9341_WHITE);
}
// Draw the 12, 3, 6, and 9 numbers
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.setCursor(centerX - 10, centerY - clockRadius + 10); tft.print("12");
tft.setCursor(centerX + clockRadius - 20, centerY - 8); tft.print("3");
tft.setCursor(centerX - 10, centerY + clockRadius - 30); tft.print("6");
tft.setCursor(centerX - clockRadius + 10, centerY - 8); tft.print("9");
// Draw the hands statically (you will later need to update this with the actual time)
// Hour hand
tft.drawLine(centerX, centerY, centerX - 20, centerY + 20, ILI9341_WHITE);
// Minute hand
tft.drawLine(centerX, centerY, centerX + 50, centerY, ILI9341_WHITE);
// Second hand
tft.drawLine(centerX, centerY, centerX, centerY - 70, ILI9341_RED);
// Draw the digital time
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(80, 260); // Adjust as necessary for your display
tft.print("14:47:01");
// Draw the digital date
tft.setTextSize(1);
tft.setCursor(100, 280); // Adjust as necessary for your display
tft.print("14.12.2016");
}