#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);
int maxSquaresX;
int maxSquaresY;
int squareSizeX;
int squareSizeY;
uint16_t rainbowColors[] = {ILI9341_RED, ILI9341_ORANGE, ILI9341_YELLOW, ILI9341_GREEN,
ILI9341_BLUE, tft.color565(75,0,130), tft.color565(238,130,238)};
void setup() {
// Initialize TFT display
tft.begin();
// Set the color mode to use RGB values
tft.setRotation(3); // Adjust the rotation if needed
// Get the dimensions of the TFT screen
int screenWidth = tft.width();
int screenHeight = tft.height();
// Calculate the maximum number of squares in both dimensions
maxSquaresX = screenWidth / 20; // Adjust the divisor as needed
maxSquaresY = screenHeight / 20; // Adjust the divisor as needed
// Draw the big square
tft.fillScreen(ILI9341_WHITE);
tft.drawRect(0, 0, screenWidth, screenHeight, ILI9341_BLACK);
// Draw and fill the small squares with rainbow colors
squareSizeX = screenWidth / maxSquaresX;
squareSizeY = screenHeight / maxSquaresY;
for (int i = 0; i < maxSquaresY; i++) {
for (int j = 0; j < maxSquaresX; j++) {
int x = j * squareSizeX;
int y = i * squareSizeY;
tft.fillRect(x, y, squareSizeX, squareSizeY, rainbowColors[(i * maxSquaresX + j) % 7]);
}
}
// Print the total number of squares to the serial monitor
Serial.begin(9600);
}
void loop() {
// Gradually shift the colors
for (int shift = 0; shift < 7; shift++) {
for (int i = 0; i < maxSquaresY; i++) {
for (int j = 0; j < maxSquaresX; j++) {
int x = j * squareSizeX;
int y = i * squareSizeY;
tft.fillRect(x, y, squareSizeX, squareSizeY, rainbowColors[((i * maxSquaresX + j) + shift) % 7]);
}
}
delay(500); // Adjust the delay as needed for the desired animation speed
}
}
tft code by arvind.
अरविन्द पाटील 23/11/23 .