#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 8
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Define colors (16-bit RGB values)
uint16_t rainbow_colors[] = {
ILI9341_RED,
ILI9341_ORANGE,
ILI9341_YELLOW,
ILI9341_GREEN,
ILI9341_BLUE,
ILI9341_MAGENTA,
ILI9341_CASET
};
int color_index = 0;
void setup() {
tft.begin();
tft.setRotation(3); // Set the rotation as needed
tft.fillScreen(ILI9341_BLACK);
}
void drawConcentricCircles() {
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
int radius = 150; // Starting radius
int delayTime = 200 * 4 / 3; // Decrease speed by one-third
// Draw circles with decreasing radii
while (radius > 0) {
tft.drawCircle(centerX, centerY, radius, rainbow_colors[color_index]);
color_index = (color_index + 1) % 7; // Cycle through the rainbow colors
radius -= 20; // Reduce the radius by 20 pixels
delay(delayTime); // Add a small delay to see the animation effect
}
// Draw circles with increasing radii
radius = 20; // Starting radius for increasing circles
while (radius <= 150) {
tft.drawCircle(centerX, centerY, radius, rainbow_colors[color_index]);
color_index = (color_index + 1) % 7; // Cycle through the rainbow colors
radius += 20; // Increase the radius by 20 pixels
delay(delayTime); // Add a small delay to see the animation effect
}
}
void drawConcentricSquares() {
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
int sideLength = 200; // Starting side length
int delayTime = 200 * 4 / 3; // Decrease speed by one-third
// Draw squares with decreasing side lengths
while (sideLength > 0) {
tft.drawRect(centerX - sideLength / 2, centerY - sideLength / 2, sideLength, sideLength, rainbow_colors[color_index]);
color_index = (color_index + 1) % 7; // Cycle through the rainbow colors
sideLength -= 20; // Reduce the side length by 20 pixels
delay(delayTime); // Add a small delay to see the animation effect
}
// Draw squares with increasing side lengths
sideLength = 20; // Starting side length for increasing squares
while (sideLength <= 200) {
tft.drawRect(centerX - sideLength / 2, centerY - sideLength / 2, sideLength, sideLength, rainbow_colors[color_index]);
color_index = (color_index + 1) % 7; // Cycle through the rainbow colors
sideLength += 20; // Increase the side length by 20 pixels
delay(delayTime); // Add a small delay to see the animation effect
}
}
void loop() {
// Draw concentric circles
drawConcentricCircles();
// Pause before clearing the screen and drawing squares
delay(1000);
tft.fillScreen(ILI9341_BLACK); // Clear the screen
// Draw concentric squares
drawConcentricSquares();
// Display "CODE BY ARVIND" after drawing the squares
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(centerX - 50, centerY + 100); // Adjust position as needed
tft.print("CODE BY ARVIND");
// Pause before restarting the loop
delay(1000);
tft.fillScreen(ILI9341_BLACK); // Clear the screen
}