#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(3); // Adjust the rotation if needed
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
// Draw square with reducing side lengths and rainbow background
for (int side_length = 200; side_length > 0; side_length -= 20) {
// Change background to rainbow colors
drawRainbowBackground();
// Set the TFT color to red
uint16_t color = tft.color565(255, 0, 0);
// Draw the square
tft.fillRect(tft.width() / 2 - side_length / 2, tft.height() / 2 - side_length / 2, side_length, side_length, color);
delay(500); // Adjust delay if needed
// Clear the square by filling it with the background color
tft.fillRect(tft.width() / 2 - side_length / 2, tft.height() / 2 - side_length / 2, side_length, side_length, ILI9341_BLACK);
}
// Draw attractive design from code2
for (int i = 0; i < 35; ++i) {
int randomRed = random(256);
int randomGreen = random(256);
int randomBlue = random(256);
uint16_t randomColor = tft.color565(randomRed, randomGreen, randomBlue);
tft.setTextColor(randomColor);
tft.drawCircle(160, 120, 100, randomColor);
tft.setRotation(3); // Adjust the rotation if needed
delay(100); // Adjust the delay to control the drawing speed
tft.fillScreen(ILI9341_BLACK); // Clear the screen for the next circle
}
}
void drawRainbowBackground() {
// Draw rainbow background
for (int i = 0; i < tft.width(); ++i) {
int hue = map(i, 0, tft.width(), 0, 255);
uint16_t color = tft.color565(hue, 255, 255);
tft.drawFastVLine(i, 0, tft.height(), color);
}
delay(500); // Adjust delay if needed
}
combined two codes as one by arvind.
अरविन्द पाटील 1/12/23 .