#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <WiFi.h>
#include <time.h>
// =====================================================
// CYD ESP32-2432S028
// EXTREME GRAPHICS CAPABILITY SHOWCASE
// =====================================================
// ---------------- TFT PINS ----------------
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 13
#define TFT_MISO 12
#define TFT_SCK 14
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// ---------------- RGB LED -----------------
#define LED_R 4
#define LED_G 16
#define LED_B 17
// ---------------- DISPLAY -----------------
#define W 320
#define H 240
// =====================================================
// RGB CONTROL
// =====================================================
void setRGB(bool r, bool g, bool b) {
digitalWrite(LED_R, r ? LOW : HIGH);
digitalWrite(LED_G, g ? LOW : HIGH);
digitalWrite(LED_B, b ? LOW : HIGH);
}
// =====================================================
// FAST GRADIENT
// =====================================================
void gradientBG() {
for (int y = 0; y < H; y++) {
uint8_t r = map(y, 0, H, 0, 255);
uint8_t g = map(y, 0, H, 50, 0);
uint8_t b = map(y, 0, H, 255, 40);
tft.drawFastHLine(
0,
y,
W,
tft.color565(r, g, b)
);
}
}
// =====================================================
// RAINBOW LINES
// =====================================================
void rainbowLines() {
tft.fillScreen(ILI9341_BLACK);
int cx = W / 2;
int cy = H / 2;
for (int a = 0; a < 360; a += 2) {
float rad = a * DEG_TO_RAD;
int x = cx + cos(rad) * 160;
int y = cy + sin(rad) * 120;
uint16_t c = tft.color565(
127 + 127 * sin(rad),
127 + 127 * sin(rad + 2),
127 + 127 * sin(rad + 4)
);
tft.drawLine(cx, cy, x, y, c);
}
}
// =====================================================
// RANDOM CIRCLES
// =====================================================
void circlesFX() {
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < 80; i++) {
int x = random(W);
int y = random(H);
int r = random(5, 35);
uint16_t c = tft.color565(
random(255),
random(255),
random(255)
);
tft.fillCircle(x, y, r, c);
tft.drawCircle(x, y, r, ILI9341_WHITE);
}
}
// =====================================================
// RANDOM TRIANGLES
// =====================================================
void trianglesFX() {
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < 60; i++) {
int x1 = random(W);
int y1 = random(H);
int x2 = random(W);
int y2 = random(H);
int x3 = random(W);
int y3 = random(H);
uint16_t c = tft.color565(
random(255),
random(255),
random(255)
);
tft.fillTriangle(
x1, y1,
x2, y2,
x3, y3,
c
);
tft.drawTriangle(
x1, y1,
x2, y2,
x3, y3,
ILI9341_WHITE
);
}
}
// =====================================================
// RANDOM RECTANGLES
// =====================================================
void rectanglesFX() {
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < 70; i++) {
int x = random(W);
int y = random(H);
int w = random(20, 120);
int h = random(20, 90);
uint16_t c = tft.color565(
random(255),
random(255),
random(255)
);
tft.fillRect(x, y, w, h, c);
tft.drawRect(x, y, w, h, ILI9341_WHITE);
}
}
// =====================================================
// SPIRAL EFFECT
// =====================================================
void spiralFX() {
tft.fillScreen(ILI9341_BLACK);
float angle = 0;
float radius = 1;
int cx = W / 2;
int cy = H / 2;
while (radius < 120) {
int x = cx + cos(angle) * radius;
int y = cy + sin(angle) * radius;
uint16_t c = tft.color565(
127 + 127 * sin(angle),
127 + 127 * sin(angle + 2),
127 + 127 * sin(angle + 4)
);
tft.fillCircle(x, y, 2, c);
angle += 0.18;
radius += 0.12;
}
}
// =====================================================
// PIXEL BLAST
// =====================================================
void pixelBlast() {
tft.fillScreen(ILI9341_BLACK);
for (long i = 0; i < 25000; i++) {
int x = random(W);
int y = random(H);
uint16_t c = tft.color565(
random(255),
random(255),
random(255)
);
tft.drawPixel(x, y, c);
}
}
// =====================================================
// WAVE ANIMATION
// =====================================================
void waveFX() {
tft.fillScreen(ILI9341_BLACK);
for (int x = 0; x < W; x++) {
float y1 = 120 + sin(x * 0.08) * 50;
float y2 = 120 + cos(x * 0.06) * 40;
tft.drawLine(
x,
120,
x,
y1,
ILI9341_CYAN
);
tft.drawLine(
x,
120,
x,
y2,
ILI9341_MAGENTA
);
}
}
// =====================================================
// STARFIELD
// =====================================================
void starfieldFX() {
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < 5000; i++) {
int x = random(W);
int y = random(H);
int b = random(100,255);
uint16_t c = tft.color565(b,b,b);
tft.drawPixel(x, y, c);
}
}
// =====================================================
// SETUP
// =====================================================
void setup() {
Serial.begin(115200);
SPI.begin(
TFT_SCK,
TFT_MISO,
TFT_MOSI,
TFT_CS
);
tft.begin();
tft.setRotation(1);
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
setRGB(false, false, false);
randomSeed(analogRead(0));
gradientBG();
delay(1000);
}
// =====================================================
// LOOP
// =====================================================
void loop() {
// =========================================
// RAINBOW LINE ENGINE
// =========================================
setRGB(true,false,false);
rainbowLines();
delay(2200);
// =========================================
// RANDOM CIRCLES
// =========================================
setRGB(false,true,false);
circlesFX();
delay(2200);
// =========================================
// TRIANGLES
// =========================================
setRGB(false,false,true);
trianglesFX();
delay(2200);
// =========================================
// RECTANGLES
// =========================================
setRGB(true,true,false);
rectanglesFX();
delay(2200);
// =========================================
// SPIRAL
// =========================================
setRGB(true,false,true);
spiralFX();
delay(2200);
// =========================================
// PIXEL BLAST
// =========================================
setRGB(false,true,true);
pixelBlast();
delay(2200);
// =========================================
// WAVE ENGINE
// =========================================
setRGB(true,true,true);
waveFX();
delay(2200);
// =========================================
// STARFIELD
// =========================================
setRGB(true,false,false);
starfieldFX();
delay(2200);
}https://wokwi.com/projects/464273240151255041