#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(3); // Adjust the rotation if needed
// Uncomment the following line if your display is inverted
// tft.invertDisplay(true);
displayShapes();
}
void loop() {
// Nothing to do here
}
void displayShapes() {
int numColors = 7; // Number of colors in the rainbow
int shapeColor = 0; // Index of the current color
// Display square
drawSquare(20, 20, 40, getRainbowColor(shapeColor));
delay(1000);
// Display triangle
drawTriangle(120, 120, 140, getRainbowColor(shapeColor));
delay(1000);
// Display circle
drawCircle(220, 180, 40, getRainbowColor(shapeColor));
}
void drawSquare(int x, int y, int size, uint16_t color) {
tft.fillRoundRect(x, y, size, size, 0, color);
}
void drawTriangle(int x, int y, int size, uint16_t color) {
tft.fillTriangle(x, y, x + size, y, x + size / 2, y - size, color);
}
void drawCircle(int x, int y, int radius, uint16_t color) {
tft.fillCircle(x, y, radius, color);
}
uint16_t getRainbowColor(int index) {
// Rainbow color mapping (ROYGBIV)
switch (index) {
case 0: return tft.color565(255, 0, 0); // Red
case 1: return tft.color565(255, 127, 0); // Orange
case 2: return tft.color565(255, 255, 0); // Yellow
case 3: return tft.color565(0, 255, 0); // Green
case 4: return tft.color565(0, 0, 255); // Blue
case 5: return tft.color565(75, 0, 130); // Indigo
case 6: return tft.color565(148, 0, 211); // Violet
default: return tft.color565(255, 255, 255); // White (fallback)
}
}