#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 48
#define TFT_CS 53
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define RED 0xc086
#define WHITE 0xffff
#define BLUE 0x010d
void setup() {
tft.begin();
tft.setRotation(3);
}
// --- Random RGB565 color generator ---
uint16_t randomRGB565() {
uint8_t r = random(0, 32); // 5-bit red
uint8_t g = random(0, 64); // 6-bit green
uint8_t b = random(0, 32); // 5-bit blue
return (r << 11) | (g << 5) | b;
}
void loop(void) {
uint16_t randomUS = randomRGB565();
uint16_t randomUK = randomRGB565();
uint16_t randomStripes = randomRGB565();
uint16_t randomBox = randomRGB565();
uint16_t randomStars = randomRGB565();
uint16_t randomScot = randomRGB565();
uint16_t randomEng = randomRGB565();
tft.fillScreen(randomUS);
// draw stripes
for (int y = 0; y <= 222; y += 37) {
drawStripe(y, randomStripes);
}
// draw box
tft.fillRect(0, 0, 174, 129, randomBox);
// draw stars
for (int j = 3; j <= 107; j += 26) {
for (int i = 3; i <= 155; i += 30) {
drawStar(i, j, randomStars);
}
if (j < 107) {
for (int i = 18; i <= 140; i += 30) {
drawStar(i, j + 13, randomStars);
}
}
}
delay(1000);
tft.fillScreen(randomUK);
// draw white diagonals
tft.fillTriangle(0, 0, 0, 31, 279, 239, randomScot);
tft.fillTriangle(0, 0, 319, 239, 279, 239, randomScot);
tft.fillTriangle(0, 0, 36, 0, 319, 239, randomScot);
tft.fillTriangle(36, 0, 319, 239, 319, 208, randomScot);
tft.fillTriangle(0, 239, 0, 209, 279, 0, randomScot);
tft.fillTriangle(0, 239, 279, 0, 319, 0, randomScot);
tft.fillTriangle(0, 239, 319, 0, 319, 30, randomScot);
tft.fillTriangle(319, 30, 0, 239, 40, 239, randomScot);
// draw white cross
tft.fillRect(120, 0, 80, 240, randomScot);
tft.fillRect(0, 79, 320, 80, randomScot);
// draw red cross
tft.fillRect(136, 0, 48, 240, randomEng);
tft.fillRect(0, 96, 320, 48, randomEng);
// draw red diagonals
tft.fillTriangle(0, 0, 108, 79, 78, 79, randomEng);
tft.fillTriangle(0, 0, 0, 20, 78, 79, randomEng);
tft.fillTriangle(200, 69, 200, 79, 294, 0, randomEng);
tft.fillTriangle(200, 79, 294, 0, 319, 0, randomEng);
tft.fillTriangle(319, 0, 214, 79, 200, 79, randomEng);
tft.fillTriangle(210, 159, 319, 239, 319, 220, randomEng);
tft.fillTriangle(319, 220, 237, 159, 210, 159, randomEng);
tft.fillTriangle(0, 239, 107, 159, 120, 159, randomEng);
tft.fillTriangle(120, 159, 0, 239, 26, 239, randomEng);
tft.fillTriangle(26, 239, 120, 159, 120, 169, randomEng);
delay(1000);
}
void drawStar(int x, int y, uint16_t color) {
tft.fillTriangle(x + 7, y + 0, x + 9, y + 6, x + 5, y + 6, color);
tft.fillTriangle(x + 14, y + 5, x + 6, y + 11, x + 5, y + 5, color);
tft.fillTriangle(x + 12, y + 14, x + 4, y + 8, x + 9, y + 6, color);
tft.fillTriangle(x + 2, y + 14, x + 5, y + 6, x + 10, y + 8, color);
tft.fillTriangle(x + 0, y + 5, x + 9, y + 5, x + 8, y + 11, color);
}
void drawStripe(int y, uint16_t color) {
tft.fillRect(0, y, 320, 18, color);
}