#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_SCK 7
#define TFT_MOSI 11
#define MISO 9
#define TFT_CS 12
#define TFT_DC 14
#define TFT_RST 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void drawColorGradientSquare();
int colorRangeMap(int value, int in_min, int in_max, int out_min, int out_max);
void displayColorSquareGrid();
void displayColorTriangles();
void drawCircles();
void writeDiagonally();
void setup() {
Serial.begin(115200);
delay(500);
delay(1000);
// Initialize the TFT display
tft.begin();
tft.setRotation(3); // Adjust the rotation if necessary
}
void loop() {
// Display color square grid and triangles
drawColorGradientSquare();
delay(5000); // Pause for 5 seconds
tft.fillScreen(ILI9341_BLACK); // Clear the screen
displayColorSquareGrid();
delay(2500); // Pause for 2.5 seconds
tft.fillScreen(ILI9341_BLACK); // Clear the screen
displayColorTriangles();
delay(2000); // Pause for 2 seconds
tft.fillScreen(ILI9341_BLACK); // Clear the screen
// Draw the circles in rainbow colors
drawCircles();
// Write diagonally with yellow color and font size 3 by Arvind
writeDiagonally();
}
void drawColorGradientSquare() {
int centerX = 120;
int centerY = 160;
int initialSize = 120;
int sizeStep = 10;
// Draw the square with reducing size using interpolated colors
for (int size = initialSize; size > 0; size -= sizeStep) {
int halfSize = size / 2;
for (int x = centerX - halfSize; x <= centerX + halfSize; x++) {
for (int y = centerY - halfSize; y <= centerY + halfSize; y++) {
int distanceX = abs(x - centerX);
int distanceY = abs(y - centerY);
int maxDistance = max(distanceX, distanceY);
int color = colorRangeMap(maxDistance, 0, halfSize, ILI9341_RED, ILI9341_BLUE);
tft.drawPixel(x, y, color);
}
}
}
}
int colorRangeMap(int value, int in_min, int in_max, int out_min, int out_max) {
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void displayColorSquareGrid() {
int side = 150; // Initial side length of the square
int spacing = 10; // Spacing between squares
for (int i = 0; i < 10; ++i) {
uint16_t color = tft.color565(i * 20, i * 10, 255 - i * 15); // Generate a gradient color
tft.fillRect(10 + i * spacing, 10 + i * spacing, side, side, color);
side -= 5; // Reduce side length by 5 pixels for the next square
delay(2500);
}
}
void displayColorTriangles() {
int side = 240; // Initial side length of the triangle
int spacing = 30; // Spacing between triangles
for (int i = 0; i < 10; ++i) {
uint16_t color = tft.color565(i * 20, 255 - i * 10, i * 15); // Generate a gradient color
int x0 = 80 + i * spacing;
int y0 = 30 + i * spacing;
int x1 = 140 + i * spacing;
int y1 = 70 + i * spacing;
int x2 = 40 + i * spacing;
int y2 = 70 + i * spacing;
tft.fillTriangle(x0, y0, x1, y1, x2, y2, color);
side -= 5; // Reduce side length by 5 pixels for the next triangle
delay(2000);
}
}
void drawCircles() {
// Define an array of colors for the rainbow
uint16_t colors[] = {ILI9341_RED, ILI9341_ORANGE, ILI9341_YELLOW, ILI9341_GREEN, ILI9341_BLUE, ILI9341_INVCTR, ILI9341_CASET};
// Define the coordinates of the circle center
int x = tft.width() / 2;
int y = tft.height() / 2;
// Define the initial diameter of the circle
int dia = 200;
// Loop through the circle count
for (int i = 0; i < 7; i++) {
// Draw the circle with the corresponding color
tft.fillCircle(x, y, dia / 2, colors[i]);
delay(2000); // Reduce the diameter by 25 pixels
dia -= 25;
}
}
void writeDiagonally() {
// Set the text color to yellow
tft.setTextColor(ILI9341_YELLOW);
// Set the text size to 3
tft.setTextSize(3);
// Define the initial coordinates of the text
int x = 40;
int y = 60;
// Define the text to write
char text[] = "by Arvind";
// Loop through the characters of the text
for (int i = 0; i < strlen(text); i++) {
// Write the character at the current position
tft.write(text[i]);
// Move the cursor diagonally by 20 pixels
x += 20;
y += 20;
// Set the cursor to the new position
tft.setCursor(x, y);
}
}
Loading
wemos-s2-mini
wemos-s2-mini