#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define BLACK 0x0000
#define RED 0xF800
#define ORANGE 0xFD20
#define YELLOW 0xFFE0
#define GREEN 0x07E0
#define BLUE 0x001F
#define INDIGO 0x4810
#define VIOLET 0x9010
#define WHITE 0xFFFF
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
// Initializing TFT display:
tft.begin();
}
void loop() {
// Fill TFT Screen with a color:
tft.fillScreen(BLACK);
delay(500);
// Draw a rainbow square with reducing side length:
for (int side = 680; side > 0; side -= 25) {
drawRainbowSquare(20, 480, side);
delay(1000);
}
delay(2000);
// Fill the entire screen with white:
tft.fillScreen(WHITE);
delay(500);
// Draw a rainbow triangle with reducing side length:
for (int side = 220; side > 0; side -= 25) {
drawRainbowTriangle(20, 300, side);
delay(200);
}
delay(2000);
}
void drawRainbowSquare(int x, int y, int side) {
int colorArray[] = {RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET};
int numColors = sizeof(colorArray) / sizeof(colorArray[0]);
for (int i = 0; i < numColors; ++i) {
tft.fillRect(x - side / 2, y - side / 2, side, side, colorArray[i]);
delay(100);
}
}
void drawRainbowTriangle(int x, int y, int side) {
int colorArray[] = {RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET};
int numColors = sizeof(colorArray) / sizeof(colorArray[0]);
for (int i = 0; i < numColors; ++i) {
int x0 = x;
int y0 = y - side / 2;
int x1 = x - side / 2;
int y1 = y + side / 2;
int x2 = x + side / 2;
int y2 = y + side / 2;
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colorArray[i]);
delay(1000);
}
}