// =============================================================
// TFT_eSPI INTERNAL SETUP
// =============================================================
#define USER_SETUP_LOADED
#define ILI9341_DRIVER
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_MISO 12
#define TFT_MOSI 13
#define TFT_SCLK 14
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST -1
#define TFT_BL 21
#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
#define SMOOTH_FONT
#define SPI_FREQUENCY 55000000
#define SPI_READ_FREQUENCY 20000000
#include <TFT_eSPI.h>
#include <SPI.h>
#include <math.h>
TFT_eSPI tft = TFT_eSPI();
// =============================================================
// RGB LED
// =============================================================
#define LED_R 4
#define LED_G 16
#define LED_B 17
void ledColor(bool r, bool g, bool b) {
digitalWrite(LED_R, !r);
digitalWrite(LED_G, !g);
digitalWrite(LED_B, !b);
}
// =============================================================
#define W 320
#define H 240
// =============================================================
// TITLE BAR
// =============================================================
void titleBar(const char* txt, uint16_t col = TFT_CYAN) {
tft.fillRect(0, 0, W, 22, TFT_NAVY);
tft.drawFastHLine(0, 22, W, col);
tft.setTextFont(2);
tft.setTextColor(col, TFT_NAVY);
tft.setCursor(8, 4);
tft.print(txt);
tft.setCursor(W - 95, 4);
tft.print("AI Centre");
}
// =============================================================
// SPLASH SCREEN
// =============================================================
void splash() {
for (int y = 0; y < H; y++) {
uint8_t r = map(y, 0, H, 10, 120);
uint8_t g = map(y, 0, H, 0, 40);
uint8_t b = map(y, 0, H, 80, 255);
tft.drawFastHLine(
0,
y,
W,
tft.color565(r, g, b)
);
}
tft.setTextDatum(MC_DATUM);
tft.setTextFont(4);
tft.setTextColor(TFT_WHITE);
tft.drawString("CYD ESP32-2432S028", W/2, 80);
tft.setTextFont(7);
tft.setTextColor(TFT_GOLD);
tft.drawString("GRAPHICS", W/2, 135);
tft.setTextFont(2);
tft.setTextColor(TFT_CYAN);
tft.drawString(
"AI Centre Nandurbar | Arvind Patil",
W/2,
190
);
delay(2500);
}
// =============================================================
// RADIAL GRADIENT
// =============================================================
void testRadialGradient() {
tft.fillScreen(TFT_BLACK);
titleBar("RADIAL GRADIENT");
int cx = W / 2;
int cy = H / 2;
for (int r = 160; r > 0; r--) {
uint8_t red = map(r, 0, 160, 255, 0);
uint8_t green = map(r, 0, 160, 0, 255);
uint8_t blue = map(r, 0, 160, 255, 30);
tft.fillCircle(
cx,
cy,
r,
tft.color565(red, green, blue)
);
}
tft.setTextDatum(MC_DATUM);
tft.setTextFont(4);
tft.setTextColor(TFT_WHITE);
tft.drawString("RADIAL FX", cx, cy);
delay(1800);
}
// =============================================================
// DIAGONAL GRADIENT
// =============================================================
void testDiagonalGradient() {
titleBar("DIAGONAL GRADIENT");
for (int y = 24; y < H; y++) {
for (int x = 0; x < W; x++) {
uint8_t r = map(x + y, 0, W + H, 0, 255);
uint8_t g = map(x, 0, W, 255, 0);
uint8_t b = map(y, 0, H, 50, 255);
tft.drawPixel(
x,
y,
tft.color565(r, g, b)
);
}
}
delay(1800);
}
// =============================================================
// TRIANGLE ART
// =============================================================
void testTriangleArt() {
tft.fillScreen(TFT_BLACK);
titleBar("TRIANGLE ART");
for (int i = 0; i < 90; i++) {
int x1 = random(W);
int y1 = random(24, H);
int x2 = random(W);
int y2 = random(24, H);
int x3 = random(W);
int y3 = random(24, H);
uint16_t c = tft.color565(
random(50,255),
random(50,255),
random(50,255)
);
tft.fillTriangle(
x1,y1,
x2,y2,
x3,y3,
c
);
tft.drawTriangle(
x1,y1,
x2,y2,
x3,y3,
TFT_WHITE
);
}
delay(1800);
}
// =============================================================
// HEXAGON
// =============================================================
void drawHexagon(int cx, int cy, int r, uint16_t col) {
int px[6];
int py[6];
for (int i = 0; i < 6; i++) {
float ang = DEG_TO_RAD * (60 * i);
px[i] = cx + cos(ang) * r;
py[i] = cy + sin(ang) * r;
}
for (int i = 0; i < 6; i++) {
int j = (i + 1) % 6;
tft.drawLine(
px[i], py[i],
px[j], py[j],
col
);
}
}
// =============================================================
// HEXAGON GRID
// =============================================================
void testHexagons() {
tft.fillScreen(TFT_BLACK);
titleBar("HEXAGON GRID");
for (int y = 40; y < H; y += 34) {
for (int x = 20; x < W; x += 36) {
uint16_t c = tft.color565(
random(50,255),
random(50,255),
random(50,255)
);
drawHexagon(x, y, 14, c);
}
}
delay(1800);
}
// =============================================================
// NEON WAVE
// =============================================================
void testNeonWave() {
tft.fillScreen(TFT_BLACK);
titleBar("NEON WAVE");
for (int x = 0; x < W; x++) {
float y1 = sin(x * 0.05) * 40;
float y2 = cos(x * 0.04) * 30;
int yy1 = H/2 + y1;
int yy2 = H/2 + y2;
tft.drawPixel(
x,
yy1,
tft.color565(255,0,255)
);
tft.drawPixel(
x,
yy2,
tft.color565(0,255,255)
);
tft.drawLine(
x,
yy1,
x,
yy2,
tft.color565(0,100,255)
);
}
delay(1800);
}
// =============================================================
// STARFIELD
// =============================================================
void testStarfield() {
tft.fillScreen(TFT_BLACK);
titleBar("STARFIELD");
for (int i = 0; i < 1500; i++) {
int x = random(W);
int y = random(24, H);
uint8_t b = random(100,255);
uint16_t c = tft.color565(b,b,b);
tft.drawPixel(x, y, c);
if (random(10) > 7) {
tft.drawPixel(x+1, y, c);
tft.drawPixel(x, y+1, c);
}
}
delay(1800);
}
// =============================================================
// SPIRAL
// =============================================================
void testSpiral() {
tft.fillScreen(TFT_BLACK);
titleBar("COLOR SPIRAL");
float angle = 0;
float radius = 2;
int cx = W/2;
int cy = H/2;
while (radius < 120) {
int x = cx + cos(angle) * radius;
int y = cy + sin(angle) * radius;
uint8_t r = 127 + 127 * sin(angle);
uint8_t g = 127 + 127 * sin(angle + 2);
uint8_t b = 127 + 127 * sin(angle + 4);
tft.fillCircle(
x,
y,
2,
tft.color565(r,g,b)
);
angle += 0.15;
radius += 0.08;
}
delay(1800);
}
// =============================================================
// FPS BALLS
// =============================================================
struct Ball {
float x;
float y;
float vx;
float vy;
int r;
uint16_t c;
};
#define BALLS 12
Ball ball[BALLS];
float fps = 0;
// =============================================================
void testBalls() {
tft.fillScreen(TFT_BLACK);
titleBar("FPS BALL TEST");
for (int i = 0; i < BALLS; i++) {
ball[i].x = random(20, W-20);
ball[i].y = random(40, H-20);
ball[i].vx = random(10,30)/10.0 * (random(2)?1:-1);
ball[i].vy = random(10,30)/10.0 * (random(2)?1:-1);
ball[i].r = random(8,18);
ball[i].c = tft.color565(
random(80,255),
random(80,255),
random(80,255)
);
}
uint32_t frames = 0;
uint32_t start = millis();
while (millis() - start < 4000) {
for (int i = 0; i < BALLS; i++) {
tft.fillCircle(
ball[i].x,
ball[i].y,
ball[i].r + 1,
TFT_BLACK
);
}
for (int i = 0; i < BALLS; i++) {
ball[i].x += ball[i].vx;
ball[i].y += ball[i].vy;
if (ball[i].x < ball[i].r ||
ball[i].x > W - ball[i].r)
ball[i].vx *= -1;
if (ball[i].y < 24 + ball[i].r ||
ball[i].y > H - ball[i].r)
ball[i].vy *= -1;
}
for (int i = 0; i < BALLS; i++) {
tft.fillCircle(
ball[i].x,
ball[i].y,
ball[i].r,
ball[i].c
);
tft.drawCircle(
ball[i].x,
ball[i].y,
ball[i].r,
TFT_WHITE
);
}
frames++;
float elapsed =
(millis() - start) / 1000.0;
fps = frames / elapsed;
char buf[32];
sprintf(buf, "%.1f FPS", fps);
tft.fillRect(200, 4, 110, 16, TFT_NAVY);
tft.setTextFont(2);
tft.setTextColor(TFT_WHITE, TFT_NAVY);
tft.setCursor(210, 4);
tft.print(buf);
}
}
// =============================================================
// SUMMARY
// =============================================================
void summary() {
tft.fillScreen(TFT_BLACK);
titleBar("GRAPHICS COMPLETE", TFT_GREEN);
tft.setTextDatum(TL_DATUM);
tft.setTextFont(4);
tft.setTextColor(TFT_GOLD);
tft.drawString("RESULTS", 12, 40);
tft.setTextFont(2);
tft.setTextColor(TFT_CYAN);
tft.drawString("Display : ILI9341", 12, 90);
tft.drawString("Board : ESP32 CYD", 12, 115);
tft.drawString("SPI : 55 MHz", 12, 140);
char buf[32];
sprintf(buf, "FPS : %.1f", fps);
tft.drawString(buf, 12, 165);
tft.setTextColor(TFT_GREEN);
tft.drawString(
"AI Centre Nandurbar",
12,
205
);
delay(5000);
}
// =============================================================
// SETUP
// =============================================================
void setup() {
Serial.begin(115200);
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
ledColor(false, false, true);
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
randomSeed(analogRead(0));
ledColor(false, true, false);
splash();
}
// =============================================================
// LOOP
// =============================================================
void loop() {
ledColor(true, false, false);
testRadialGradient();
testDiagonalGradient();
testTriangleArt();
testHexagons();
testNeonWave();
testStarfield();
testSpiral();
testBalls();
summary();
ledColor(false, true, false);
}https://wokwi.com/projects/462363419595255809