#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
RTC_DS3231 rtc;
#define BLACK 0x0000
#define YELLOW 0xFFE0
#define BLUE 0x001F
#define GREEN 0x07E0
#define RED 0xF800
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define ORANGE 0xFD20
// Array of rainbow colors
uint16_t rainbowColors[] = {RED, ORANGE, YELLOW, GREEN, CYAN, BLUE, MAGENTA};
void setup() {
Serial.begin(9600);
Serial.println("Initializing...");
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
tft.init(TFT_WIDTH, TFT_HEIGHT);
tft.setRotation(2);
tft.fillScreen(BLACK); // Clear the screen
Serial.println("Display initialized.");
}
void loop() {
DateTime now = rtc.now();
// Clear the area where the digital clock will be displayed
tft.fillRect(0, 0, TFT_WIDTH, TFT_HEIGHT, WDIE);
// Cycle through rainbow colors based on the current second
uint16_t currentColor = rainbowColors[now.second() % 7];
// Display digital time on TFT with the rainbow color
tft.setCursor(40, 130);
tft.setTextSize(4);
tft.setTextColor(currentColor);
if (now.hour() < 10) tft.print('0'); // Add leading zero
tft.print(now.hour());
tft.print(':');
if (now.minute() < 10) tft.print('0'); // Add leading zero
tft.print(now.minute());
tft.print(':');
if (now.second() < 10) tft.print('0'); // Add leading zero
tft.print(now.second());
// Display "Arvind" in the same rainbow color
tft.setCursor(60, 200);
tft.setTextSize(2);
tft.setTextColor(currentColor);
tft.print("Arvind");
// Draw the laughing emoji
drawLaughingEmoji(180, 70); // Position the emoji at (180, 70)
delay(5000); // Update every second
}
void drawLaughingEmoji(int x, int y) {
// Draw the face (yellow circle)
tft.fillCircle(x, y, 30, YELLOW);
// Draw the eyes (blue circles)
tft.fillCircle(x - 10, y - 10, 5, BLUE);
tft.fillCircle(x + 10, y - 10, 5, BLUE);
// Draw the mouth (simple arc approximation using lines)
tft.drawLine(x - 15, y + 10, x - 5, y + 20, BLACK);
tft.drawLine(x - 5, y + 20, x + 5, y + 20, BLACK);
tft.drawLine(x + 5, y + 20, x + 15, y + 10, BLACK);
// Draw the tears (blue drops)
tft.fillCircle(x - 15, y - 5, 4, BLUE);
tft.fillCircle(x + 15, y - 5, 4, BLUE);
}