#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
#define TFT_LED 7
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void clearScreen(uint16_t backgroundColor) {
tft.fillScreen(backgroundColor);
}
void animate1() {
int x = 160;
int y = 50;
int size = 20;
uint16_t color = tft.color565(255, 255, 0);
clearScreen(ILI9341_BLACK);
tft.fillTriangle(x, y, x - size, y + size, x + size, y + size, color);
delay(2000);
}
void animate2() {
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
int radius = tft.width() / 2;
int colorStep = 5;
while (radius > 0) {
clearScreen(ILI9341_BLACK);
for (int i = 0; i < 360; i++) {
int x = centerX + radius * cos(i * PI / 180.0);
int y = centerY + radius * sin(i * PI / 180.0);
uint16_t color = tft.color565(
255 * (1 + sin(colorStep * i * PI / 180.0)) / 2,
255 * (1 + sin(colorStep * (i + 120) * PI / 180.0)) / 2,
255 * (1 + sin(colorStep * (i + 240) * PI / 180.0)) / 2
);
tft.drawPixel(x, y, color);
}
radius -= 5;
delay(50);
}
}
void animate3() {
int x = 0;
int y = 0;
int size = 15;
int colorStep = 10;
clearScreen(ILI9341_BLACK);
for (int i = 0; i < tft.width(); i += size) {
for (int j = 0; j < tft.height(); j += size) {
uint16_t color = tft.color565(0, x % 256, y % 256);
tft.fillRect(i, j, size, size, color);
x += colorStep;
y += colorStep;
}
}
delay(2000);
}
void animate4() {
int x = 0;
int y = 0;
int size = 10;
int colorStep = 5;
clearScreen(ILI9341_BLACK);
for (int i = 0; i < tft.width(); i += size) {
for (int j = 0; j < tft.height(); j += size) {
uint16_t color = tft.color565(x % 256, y % 256, 0);
tft.drawPixel(i, j, color);
x += colorStep;
y += colorStep;
}
}
delay(2000);
}
void setup() {
tft.begin();
tft.setRotation(3);
pinMode(TFT_LED, OUTPUT);
digitalWrite(TFT_LED, HIGH);
animate1();
animate2();
animate3();
animate4();
}
void loop() {
// Your main code (if any) goes here
}