#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
tft.begin();
tft.setRotation(3);
}
void loop() {
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextSize(4);
displayRainbowText("Dt ", now.year(), '/', now.month(), '/', now.day());
tft.setCursor(0, 60);
displayRainbowText("Day: ", daysOfTheWeek[now.dayOfTheWeek()]);
tft.setCursor(0, 110);
displayRainbowText("Time ", now.hour(), ':', now.minute(), ':', now.second());
tft.setTextSize(3);
tft.setTextColor(tft.color565(255, 255, 55)); // Set text color to yellow
tft.setCursor(0, 160);
tft.print(" by ARVIND PATIL");
delay(3000);
}
void displayRainbowText(const char* prefix, int value1, char separator1, int value2, char separator2, int value3) {
char buffer[20];
sprintf(buffer, "%s%d%c%d%c%d", prefix, value1, separator1, value2, separator2, value3);
for (int i = 0; i < strlen(buffer); ++i) {
uint16_t color = Wheel(map(i, 0, strlen(buffer) - 1, 0, 255));
tft.setTextColor(color);
tft.print(buffer[i]);
}
}
void displayRainbowText(const char* prefix, const char* value) {
for (int i = 0; i < strlen(value); ++i) {
uint16_t color = Wheel(map(i, 0, strlen(value) - 1, 0, 255));
tft.setTextColor(color);
tft.print(value[i]);
}
}
uint16_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return tft.color565(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return tft.color565(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return tft.color565(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
https://wokwi.com/projects/384370239811996673 get code.
अरविन्द पाटील इंद्रधनुषयी घडयाळ 17/12/23 .