// =====================================================
// ESP32-C3 Mini + ILI9341 TFT Mega Demo
// 12 Static Scenes + 3 Animated Scenes
// =====================================================
#define USER_SETUP_ID 0x9341
#define ILI9341_DRIVER
// ✅ Correct Pin Mapping (ESP32-C3 Mini)
#define TFT_MISO 4 // MISO
#define TFT_MOSI 6 // MOSI
#define TFT_SCLK 7 // SCLK
#define TFT_CS 10 // Chip Select
#define TFT_DC 9 // Data/Command
#define TFT_RST 8 // Reset
//#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
#define SPI_FREQUENCY 27000000
#include <TFT_eSPI.h>
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI();
// --------------------
// Animated Ball Vars
// --------------------
int ballX = 40, ballY = 40;
int ballDX = 3, ballDY = 2;
int ballRadius = 10;
// Custom Colors
uint16_t PINK = TFT_eSPI().color565(255, 105, 180);
// --------------------
// Static Scenes
// --------------------
void sceneLines() {
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < tft.width(); i += 10) {
tft.drawLine(i, 0, i, tft.height(), TFT_RED);
}
}
void sceneRectangles() {
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 100; i += 10) {
tft.drawRect(40, 40, i, i, TFT_GREEN);
}
}
void sceneCircles() {
tft.fillScreen(TFT_BLACK);
for (int r = 10; r < 100; r += 10) {
tft.fillCircle(120, 160, r, TFT_BLUE);
}
}
void sceneTriangles() {
tft.fillScreen(TFT_BLACK);
tft.fillTriangle(40, 200, 120, 40, 200, 200, TFT_MAGENTA);
}
void sceneText() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("ESP32-C3 + ILI9341", 20, 100, 4);
}
void sceneRainbow() {
for (int y = 0; y < tft.height(); y++) {
uint16_t color = tft.color565(y * 2, 255 - y, y);
tft.drawFastHLine(0, y, tft.width(), color);
}
}
void sceneCheckerboard() {
tft.fillScreen(TFT_BLACK);
for (int y = 0; y < tft.height(); y += 20) {
for (int x = 0; x < tft.width(); x += 20) {
if ((x + y) % 40 == 0) {
tft.fillRect(x, y, 20, 20, TFT_YELLOW);
} else {
tft.fillRect(x, y, 20, 20, TFT_CYAN);
}
}
}
}
void sceneArcs() {
tft.fillScreen(TFT_BLACK);
tft.drawCircle(120, 160, 60, TFT_WHITE);
tft.drawLine(120, 160, 180, 160, TFT_RED);
tft.drawLine(120, 160, 120, 100, TFT_GREEN);
}
void scenePolygon() {
tft.fillScreen(TFT_BLACK);
tft.fillTriangle(60, 60, 180, 60, 120, 180, TFT_ORANGE);
}
void sceneFonts() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Font2 Demo", 10, 40, 2);
tft.drawString("Font4 Demo", 10, 80, 4);
tft.drawString("Font6 Demo", 10, 120, 6);
}
void sceneSprite() {
tft.fillScreen(TFT_BLACK);
tft.fillCircle(100, 100, 30, PINK);
tft.fillRect(140, 140, 40, 40, TFT_GREEN);
}
void sceneBranding() {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.drawString("AI Centre Nandurbar", 40, 120, 4);
}
// --------------------
// Animated Scenes
// --------------------
void sceneBouncingBall() {
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 200; i++) {
tft.fillCircle(ballX, ballY, ballRadius, TFT_RED);
delay(20);
tft.fillCircle(ballX, ballY, ballRadius, TFT_BLACK); // erase
ballX += ballDX;
ballY += ballDY;
if (ballX - ballRadius < 0 || ballX + ballRadius > tft.width()) ballDX = -ballDX;
if (ballY - ballRadius < 0 || ballY + ballRadius > tft.height()) ballDY = -ballDY;
}
}
void sceneScrollingText() {
tft.fillScreen(TFT_BLACK);
for (int x = tft.width(); x > -200; x -= 5) {
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.drawString("Welcome to ESP32-C3 Demo!", x, 100, 4);
delay(30);
}
}
void sceneColorFade() {
for (int i = 0; i < 255; i += 5) {
uint16_t color = tft.color565(i, 255 - i, i / 2);
tft.fillScreen(color);
delay(50);
}
}
// --------------------
// Setup & Loop
// --------------------
void setup() {
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
}
void loop() {
// Static gallery
sceneLines(); delay(1000);
sceneRectangles(); delay(1000);
sceneCircles(); delay(1000);
sceneTriangles(); delay(1000);
sceneText(); delay(1000);
sceneRainbow(); delay(1000);
sceneCheckerboard(); delay(1000);
sceneArcs(); delay(1000);
scenePolygon(); delay(1000);
sceneFonts(); delay(1000);
sceneSprite(); delay(1000);
sceneBranding(); delay(1000);
// Animated gallery
sceneBouncingBall();
sceneScrollingText();
sceneColorFade();
}
Loading
xiao-esp32-c3
xiao-esp32-c3