/*******************************************************
Explanation:
Initialization:
The display is initialized and cleared in the setup() function.
Draw Circles:
The drawConcentricCircles function draws circles with decreasing and increasing radii,
cycling through the colors in the rainbow_colors array.
Draw Squares:
The drawConcentricSquares function draws squares with decreasing and increasing side
lengths, similarly cycling through the colors in the rainbow_colors array.
Draw Triangles:
The drawConcentricTriangles function draws triangles with decreasing and increasing
side lengths, similarly cycling through the colors in the rainbow_colors array.
The drawTriangle function calculates the vertices of the triangle and draws it
using tft.drawLine.
Loop Function:
The loop function handles the animation sequence.
It first calls drawConcentricCircles(), then pauses for 1 second.
The screen is cleared, and drawConcentricSquares() is called.
After the squares are drawn, the screen is cleared again, and drawConcentricTriangles()
is called.
After the triangles are drawn, the message "CODE BY ARVIND" is displayed at
the bottom of the screen.
The loop then pauses for another second before clearing the screen and starting over.
Upload this code to your Arduino, and it should display a series of concentric
circles, clear the screen, display concentric squares, clear the screen again,
display concentric triangles, and then show the text "CODE BY ARVIND".
Adjust the initial sizes and increment/decrement values as
needed for yourspecific display size and preferences.
https://chatgpt.com/share/b2b4a17a-371b-4f12-85ac-a13b55c95c61
BY ARVIND PATIL 5/8/2024
*********************************************************/
#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 = 150; // 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 <= 150) {
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 drawConcentricTriangles() {
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
int sideLength = 150; // Starting side length
int delayTime = 200 * 4 / 3; // Decrease speed by one-third
// Draw triangles with decreasing side lengths
while (sideLength > 0) {
drawTriangle(centerX, centerY, 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 triangles with increasing side lengths
sideLength = 20; // Starting side length for increasing triangles
while (sideLength <= 150) {
drawTriangle(centerX, centerY, 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 drawTriangle(int centerX, int centerY, int sideLength, uint16_t color) {
int halfSide = sideLength / 2;
int height = (sqrt(3) / 2) * sideLength;
int x1 = centerX;
int y1 = centerY - height / 2;
int x2 = centerX - halfSide;
int y2 = centerY + height / 2;
int x3 = centerX + halfSide;
int y3 = centerY + height / 2;
tft.drawLine(x1, y1, x2, y2, color);
tft.drawLine(x2, y2, x3, y3, color);
tft.drawLine(x3, y3, x1, y1, color);
}
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();
// Pause before clearing the screen and drawing triangles
delay(1000);
tft.fillScreen(ILI9341_BLACK); // Clear the screen
// Draw concentric triangles
drawConcentricTriangles();
// Display the final message after all animations
tft.fillScreen(ILI9341_BLACK); // Clear the screen
int centerX = tft.width() / 2;
int centerY = tft.height() / 2;
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(centerX - 120, centerY - 20); // Adjust position as needed
tft.print("THIS IS REDUCING AND");
tft.setCursor(centerX - 120, centerY);
tft.print("ENLARGING SHAPES CREATED");
tft.setCursor(centerX - 120, centerY + 20);
tft.print("BY ARVIND PATIL ON 4/8/24");
tft.setCursor(centerX - 120, centerY + 60);
tft.print("https://wokwi.com/projects/405366120965295105");
// Pause for 5 seconds
delay(5000);
tft.fillScreen(ILI9341_BLACK); // Clear the screen
// Restart the loop
}