#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.h> // ILI9341 library
// Define pins for the ILI9341 display
#define TFT_CS 10 // Chip select pin
#define TFT_DC 9 // Data/Command pin
#define TFT_RST 8 // Reset pin
// Create an instance of the ILI9341 display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
// Initialize the display
tft.begin();
// Set rotation (0-3)
tft.setRotation(1); // Landscape mode
// Fill the screen with black
tft.fillScreen(ILI9341_BLACK);
// Draw some basic shapes
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Hello, ILI9341!");
tft.drawRect(50, 50, 100, 50, ILI9341_RED);
tft.fillCircle(120, 150, 30, ILI9341_BLUE);
}
void loop() {
// Animate a moving rectangle
static int x = 0;
static int dx = 2;
// Clear the previous rectangle
tft.fillRect(x, 200, 50, 20, ILI9341_BLACK);
// Update position
x += dx;
if (x <= 0 || x >= (tft.width() - 50)) {
dx = -dx; // Reverse direction
}
// Draw the new rectangle
tft.fillRect(x, 200, 50, 20, ILI9341_GREEN);
// Delay for smooth animation
delay(30);
}