#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// === PINS À ADAPTER SELON TON MONTAGE ===
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);
// === PARAMÈTRES DE LA BALLE ===
int x = 50;
int y = 50;
int dx = 3;
int dy = 2;
const int R = 8;
// === COULEURS ===
#define BG ILI9341_BLACK
#define BALL ILI9341_RED
void setup() {
tft.begin();
tft.setRotation(1); // 1 = paysage
tft.fillScreen(BG);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.print("Simulation balle");
}
void loop() {
// Effacer l’ancienne balle
tft.fillCircle(x, y, R, BG);
// Mise à jour
x += dx;
y += dy;
// Rebond horizontal
if (x <= R || x >= tft.width() - R) {
dx = -dx;
}
// Rebond vertical
if (y <= R || y >= tft.height() - R) {
dy = -dy;
}
// Dessiner la nouvelle balle
tft.fillCircle(x, y, R, BALL);
delay(15); // vitesse de l’animation
}