#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST -1
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
// DEFINE RAINBPW
#define Red: (255, 0, 0)
#define Orange: (255, 127, 0)
#define Yellow: (255, 255, 0)
#define Green: (0, 128, 0)
#define Blue: (0, 0, 255)
#define Indigo: (75, 0, 130)
#define Violet: (148, 0, 211)
int sides = 12; // Initial number of sides
int centerX = SCREEN_WIDTH / 2;
int centerY = SCREEN_HEIGHT / 2;
int radius = 100;
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(3); // Adjust the rotation if needed
}
void loop() {
drawMovingPolygon();
writeArvindInRainbow();
}
void drawMovingPolygon() {
static float angle = 0.0;
// Calculate new position of the polygon
int x1 = centerX + radius * cos(radians(angle));
int y1 = centerY + radius * sin(radians(angle));
int x2 = centerX + radius * cos(radians(angle + 60));
int y2 = centerY + radius * sin(radians(angle + 60));
int x3 = centerX + radius * cos(radians(angle + 120));
int y3 = centerY + radius * sin(radians(angle + 120));
int x4 = centerX + radius * cos(radians(angle + 180));
int y4 = centerY + radius * sin(radians(angle + 180));
int x5 = centerX + radius * cos(radians(angle + 240));
int y5 = centerY + radius * sin(radians(angle + 240));
int x6 = centerX + radius * cos(radians(angle + 300));
int y6 = centerY + radius * sin(radians(angle + 300));
// Draw the polygon by connecting the vertices with lines in rainbow colors
tft.drawLine(x1, y1, x2, y2, Wheel(map(0, 0, sides, 0, 255)));
tft.drawLine(x2, y2, x3, y3, Wheel(map(1, 0, sides, 0, 255)));
tft.drawLine(x3, y3, x4, y4, Wheel(map(2, 0, sides, 0, 255)));
tft.drawLine(x4, y4, x5, y5, Wheel(map(3, 0, sides, 0, 255)));
tft.drawLine(x5, y5, x6, y6, Wheel(map(4, 0, sides, 0, 255)));
tft.drawLine(x6, y6, x1, y1, Wheel(map(5, 0, sides, 0, 255)));
// Increment the angle for the next frame
angle += 2.0;
// Delay to control the speed of the movement
delay(2000);
}
void writeArvindInRainbow() {
int x = 20; // Starting X coordinate
int y = 220; // Starting Y coordinate
char text[] = "Arvind";
for (int i = 0; i < sizeof(text) - 1; i++) {
// Calculate rainbow color based on the position of the character in the text
uint16_t color = Wheel(map(i, 0, sizeof(text) - 2, 0, 255));
// Write the character to the TFT in rainbow color
tft.setTextColor(color);
tft.setTextSize(2);
tft.setCursor(x, y);
tft.print(text[i]);
// Increment X coordinate for the next character
x += 20;
}
}
uint16_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return tft.color565(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return tft.color565(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return tft.color565(WheelPos * 3, 255 - WheelPos * 3, 0);
}