#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Definição dos pinos para o ILI9341
#define TFT_CS 5
#define TFT_DC 21
#define TFT_RST 22
// Inicializa o display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Variáveis para o relógio
int hours = 12;
int minutes = 0;
int seconds = 0;
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1); // Ajusta a orientação
tft.fillScreen(ILI9341_BLACK);
// Mensagem inicial
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Relogio Digital");
delay(2000);
tft.fillScreen(ILI9341_BLACK); // Limpa a tela
}
void loop() {
// Atualiza o relógio
updateClock();
// Desenha o fundo do relógio
tft.fillRect(50, 100, 220, 60, ILI9341_BLACK); // Limpa a área anterior
// Configura o texto
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(4);
tft.setCursor(60, 120);
// Exibe o horário no formato HH:MM:SS
tft.printf("%02d:%02d:%02d", hours, minutes, seconds);
delay(1000); // Atualiza a cada segundo
}
void updateClock() {
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
}
if (minutes >= 60) {
minutes = 0;
hours++;
}
if (hours >= 24) {
hours = 0;
}
}