#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pin definitions (adjust for your board/shield)
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define TFT_MOSI 11
#define TFT_SCK 13
#define TFT_MISO 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Button coordinates
#define BTN1_X 30
#define BTN1_Y 200
#define BTN2_X 130
#define BTN2_Y 200
#define BTN_W 80
#define BTN_H 40
// State variables
bool running = false;
void drawHeader() {
tft.fillRect(0, 0, tft.width(), 30, ILI9341_NAVY);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 8);
tft.print("ILI9341 Arduino UI Demo");
}
void drawStatus(const char* msg) {
tft.fillRect(0, 40, tft.width(), 20, ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setCursor(10, 42);
tft.print(msg);
}
void drawButtons() {
// Start button
tft.fillRect(BTN1_X, BTN1_Y, BTN_W, BTN_H, ILI9341_GREEN);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.setCursor(BTN1_X + 10, BTN1_Y + 12);
tft.print("Start");
// Stop button
tft.fillRect(BTN2_X, BTN2_Y, BTN_W, BTN_H, ILI9341_RED);
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(BTN2_X + 10, BTN2_Y + 12);
tft.print("Stop");
}
void drawDemoGraphics() {
tft.fillCircle(80, 120, 40, ILI9341_CYAN);
tft.fillRect(160, 80, 100, 80, ILI9341_MAGENTA);
tft.drawTriangle(60, 160, 100, 200, 20, 200, ILI9341_YELLOW);
}
void setup() {
tft.begin();
tft.setRotation(1); // Landscape
tft.fillScreen(ILI9341_BLACK);
drawHeader();
drawStatus("Ready");
drawDemoGraphics();
drawButtons();
}
void loop() {
if (running) {
// Example animation: bouncing line
static int x = 0;
static int dx = 3;
tft.drawLine(x, 150, x, 170, ILI9341_WHITE);
delay(30);
tft.drawLine(x, 150, x, 170, ILI9341_BLACK); // erase
x += dx;
if (x < 0 || x > tft.width()) dx = -dx;
}
}
// In a real project, you’d add touch input handling here
// to detect taps on Start/Stop buttons and set `running = true/false`.
Loading
ili9341-cap-touch
ili9341-cap-touch