#include <SPI.h>
#include <WiFi.h>
#include <time.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// WiFi credentials
const char* ssid = "Airtel_arvi_6035";
const char* password = "air26289";
// SPI pin setup for ILI9341
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
#define TFT_CLK 18
#define TFT_MOSI 23
#define TFT_MISO 19
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// Rainbow palette
#define RAINBOW_COUNT 7
uint16_t rainbowColors[RAINBOW_COUNT] = {
tft.color565(255, 0, 0), // Red
tft.color565(255, 127, 0), // Orange
tft.color565(255, 255, 0), // Yellow
tft.color565(0, 255, 0), // Green
tft.color565(0, 0, 255), // Blue
tft.color565(75, 0, 130), // Indigo
tft.color565(148, 0, 211) // Violet
};
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected!");
configTime(19800, 0, "pool.ntp.org"); // India Standard Time
tft.begin();
tft.setRotation(1);
}
void loop() {
drawRainbow(); // Show background rainbow
displayTime(); // Show current time
delay(1000);
}
void drawRainbow() {
int barHeight = tft.height() / RAINBOW_COUNT;
for (int i = 0; i < RAINBOW_COUNT; i++) {
tft.fillRect(0, i * barHeight, tft.width(), barHeight, rainbowColors[i]);
}
}
void displayTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Time not available");
return;
}
char timeStr[16];
strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &timeinfo);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.setCursor(40, 120);
tft.print(timeStr);
}