#include <TFT_eSPI.h>
#include <SPI.h>
// Create TFT instance
TFT_eSPI tft = TFT_eSPI();
#define TFT_MISO 5
#define TFT_MOSI 4
#define TFT_SCLK 3
#define TFT_CS 10
#define TFT_DC 6
#define TFT_RST 7
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
void setup() {
tft.init();
tft.setRotation(1); // Landscape orientation, text upright
tft.fillScreen(TFT_BLACK);
// Splash screen
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("ESP32 + ILI9341 Demo", SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
delay(2000);
}
void loop() {
// Scene 1: Color bars
for (int i = 0; i < SCREEN_HEIGHT; i++) {
uint16_t color = tft.color565(i % 32 * 8, i % 64 * 4, i % 32 * 8);
tft.drawFastHLine(0, i, SCREEN_WIDTH, color);
}
delay(2000);
// Scene 2: Rainbow gradient
for (int x = 0; x < SCREEN_WIDTH; x++) {
uint16_t color = tft.color565(x % 64 * 4, 128, 255 - (x % 64 * 4));
tft.drawFastVLine(x, 0, SCREEN_HEIGHT, color);
}
delay(2000);
// Scene 3: Shapes gallery
tft.fillScreen(TFT_BLACK);
tft.fillCircle(60, 60, 40, TFT_RED);
tft.fillRect(120, 40, 80, 60, TFT_BLUE);
tft.drawTriangle(40, 200, 120, 200, 80, 120, TFT_GREEN);
delay(2000);
// Scene 4: Line burst
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 360; i += 10) {
int x = SCREEN_WIDTH/2 + cos(i * DEG_TO_RAD) * 100;
int y = SCREEN_HEIGHT/2 + sin(i * DEG_TO_RAD) * 100;
tft.drawLine(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, x, y, TFT_WHITE);
}
delay(2000);
// Scene 5: Concentric circles
tft.fillScreen(TFT_BLACK);
for (int r = 20; r < 120; r += 20) {
tft.drawCircle(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, r, tft.color565(r*2, 255-r, r));
}
delay(2000);
// Scene 6: Text showcase
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Hello ILI9341!", 10, 10, 4);
tft.drawString("AI Centre Nandurbar", 10, 60, 2);
delay(2000);
// Scene 7: Bouncing ball
for (int y = 40; y < SCREEN_HEIGHT-40; y+=5) {
tft.fillScreen(TFT_BLACK);
tft.fillCircle(SCREEN_WIDTH/2, y, 20, TFT_CYAN);
delay(50);
}
delay(1000);
// Scene 8: Star field
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 100; i++) {
int x = random(SCREEN_WIDTH);
int y = random(SCREEN_HEIGHT);
tft.drawPixel(x, y, TFT_WHITE);
}
delay(2000);
// Scene 9: Spectrum analyzer
tft.fillScreen(TFT_BLACK);
for (int x = 0; x < SCREEN_WIDTH; x+=10) {
int h = random(20, 100);
tft.fillRect(x, SCREEN_HEIGHT-h, 8, h, TFT_GREEN);
}
delay(2000);
// Scene 10: Plasma effect
tft.fillScreen(TFT_BLACK);
for (int y = 0; y < SCREEN_HEIGHT; y+=4) {
for (int x = 0; x < SCREEN_WIDTH; x+=4) {
uint16_t color = tft.color565((x*y)%255, (x+y)%255, (x*y)%128);
tft.fillRect(x, y, 4, 4, color);
}
}
delay(2000);
// Scene 11: Mandelbrot fractal
tft.fillScreen(TFT_BLACK);
for (int y = 0; y < SCREEN_HEIGHT; y+=2) {
for (int x = 0; x < SCREEN_WIDTH; x+=2) {
float cx = (x - SCREEN_WIDTH/2.0) / 80.0;
float cy = (y - SCREEN_HEIGHT/2.0) / 80.0;
float zx = 0, zy = 0;
int iter = 0;
while (zx*zx + zy*zy < 4 && iter < 32) {
float tmp = zx*zx - zy*zy + cx;
zy = 2*zx*zy + cy;
zx = tmp;
iter++;
}
tft.drawPixel(x, y, tft.color565(iter*8, iter*4, iter*2));
}
}
delay(2000);
// Scene 12: Splash screen
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("Demo Complete!", SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
delay(3000);
}
Loading
xiao-esp32-s3
xiao-esp32-s3