#include <Arduino.h>
#include <TFT_eSPI.h> // Graphics library
#include <SPI.h>
// --- Portable User Setup Override ---
#define USER_SETUP_LOADED
// CYD ESP32-2432S028 pin mapping
//#define TFT_MISO -1
//#define TFT_MOSI 23
//#define TFT_SCLK 18
//#define TFT_CS 5
//#define TFT_DC 16
//#define TFT_RST 17
//#define TFT_BL 4 // Backlight
#define TFT_MISO -1
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
#define TFT_BL 21
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define ST7789_DRIVER
TFT_eSPI tft = TFT_eSPI(); // Invoke library
void setup() {
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); // turn backlight on
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
// Show startup text
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("CYD TFT Demo", TFT_WIDTH/2, 20, 4);
}
void loop() {
// --- Graphics showcase ---
tft.fillScreen(TFT_BLACK);
// 1. Gradient rectangles
for (int i=0; i<240; i+=20) {
tft.fillRect(i, 40, 20, 40, tft.color565(i, 255-i, i/2));
}
// 2. Circles
tft.fillCircle(60, 140, 30, TFT_RED);
tft.drawCircle(180, 140, 30, TFT_GREEN);
// 3. Lines
tft.drawLine(0, 200, 240, 200, TFT_BLUE);
tft.drawLine(0, 220, 240, 260, TFT_MAGENTA);
// 4. Text in multiple fonts
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("AI Centre Nandurbar", 20, 280, 2);
delay(3000);
// --- Animation: moving box ---
for (int x=0; x<240; x+=10) {
tft.fillScreen(TFT_BLACK);
tft.fillRect(x, 100, 40, 40, TFT_CYAN);
tft.drawString("Graphics Capability!", 20, 40, 2);
delay(100);
}
}
Loading
esp32-2432s028r
esp32-2432s028r