#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST -1 // RST can be left unconnected
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(3); // Adjust the rotation if needed
tft.fillScreen(ILI9341_BLACK); // Fill the screen with black color
}
void loop() {
// Display color square grid and triangles
displayColorSquareGrid();
delay(2000); // Pause for 2 seconds
tft.fillScreen(ILI9341_BLACK); // Clear the screen
displayColorTriangles();
delay(2000); // Pause for 2 seconds
tft.fillScreen(ILI9341_BLACK); // Clear the screen
}
void displayColorSquareGrid() {
int side = 150; // Initial side length of the square
int spacing = 10; // Spacing between squares
for (int i = 0; i < 10; ++i) {
uint16_t color = tft.color565(i * 20, i * 10, 255 - i * 15); // Generate a gradient color
tft.fillRect(10 + i * spacing, 10 + i * spacing, side, side, color);
side -= 5; // Reduce side length by 5 pixels for the next square
}
}
void displayColorTriangles() {
int side = 150; // Initial side length of the triangle
int spacing = 10; // Spacing between triangles
for (int i = 0; i < 10; ++i) {
uint16_t color = tft.color565(i * 20, 255 - i * 10, i * 15); // Generate a gradient color
int x0 = 80 + i * spacing;
int y0 = 30 + i * spacing;
int x1 = 140 + i * spacing;
int y1 = 70 + i * spacing;
int x2 = 40 + i * spacing;
int y2 = 70 + i * spacing;
tft.fillTriangle(x0, y0, x1, y1, x2, y2, color);
side -= 5; // Reduce side length by 5 pixels for the next triangle
}
}