#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <TFT_eSPI.h>
#include <SPI.h>
#include "image.h"
#define TFT_CS 14
#define TFT_RST 33
#define TFT_DC 27
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(3); // 旋转屏幕方向
tft.fillScreen(ILI9341_BLACK); // 清屏
}
void loop() {
int x = 0;
int y = 0;
int dx = 1;
int dy = 1;
while (true) {
// 清除前一位置的图像
tft.fillRect(x, y, 25, 25, ILI9341_BLACK);
// 移动图像
x += dx;
y += dy;
// 检查图像是否碰到边界
if (x <= 0 || x >= SCREEN_WIDTH - 25) {
dx *= -1; // 改变方向
}
if (y <= 0 || y >= SCREEN_HEIGHT - 25) {
dy *= -1; // 改变方向
}
// 绘制图像
tft.pushImage (x,y,25,25,image_data_25x25x16);
delay(50); // 调整运动速度
}
}