#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pin connections for ESP32-C3 → ILI9341
#define TFT_CS 5 // Chip Select
#define TFT_DC 2 // Data/Command
#define TFT_RST 4 // Reset 4(or -1 if tied to EN pin)
// SPI pins (hardware SPI on ESP32-C3)
#define TFT_MOSI 7 // GPIO7
#define TFT_SCLK 6 // GPIO6
#define TFT_MISO 10 // optional, not always needed
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1); // Landscape orientation
tft.fillScreen(ILI9341_BLACK);
Serial.println("ESP32-C3 + ILI9341 Graphics Test");
}
void loop() {
// Test 1: Fill color sweep
for (int c = 0; c < 256; c += 5) {
uint16_t color = tft.color565(c, 255 - c, (c * 2) % 255);
tft.fillScreen(color);
delay(50);
}
// Test 2: Line burst
tft.fillScreen(ILI9341_BLACK);
for (int i = 0; i < tft.width(); i += 10) {
tft.drawLine(tft.width()/2, tft.height()/2, i, 0, ILI9341_RED);
tft.drawLine(tft.width()/2, tft.height()/2, i, tft.height(), ILI9341_GREEN);
}
// Test 3: Rectangles
for (int i = 0; i < 20; i++) {
int x = random(tft.width());
int y = random(tft.height());
int w = random(20, 80);
int h = random(20, 80);
uint16_t color = tft.color565(random(255), random(255), random(255));
tft.fillRect(x, y, w, h, color);
delay(100);
}
// Test 4: Circles
for (int i = 0; i < 20; i++) {
int x = random(tft.width());
int y = random(tft.height());
int r = random(10, 40);
uint16_t color = tft.color565(random(255), random(255), random(255));
tft.fillCircle(x, y, r, color);
delay(100);
}
// Test 5: Text
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setCursor(20, 40);
tft.println("ESP32-C3 + ILI9341");
tft.setTextSize(3);
tft.setCursor(20, 80);
tft.println("Graphics Demo");
delay(2000);
}