#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 4
#define TFT_CS 5
#define TFT_MOSI 6
#define TFT_CLK 7
#define TFT_CTRL 45
#define TFT_RST 48
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
const char* message = "I AM ARVIND FROM INDIA 947020336035";
int msgIndex = 0;
unsigned long previousMillis = 0;
const long interval = 100; // 🔁 Faster typing
bool ranFractal = false;
void setup() {
Serial.begin(115200);
pinMode(TFT_CTRL, OUTPUT);
digitalWrite(TFT_CTRL, HIGH);
tft.begin();
const uint8_t mode = 0x48;
tft.sendCommand(ILI9341_MADCTL, &mode, 1);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(88, 40);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println("ESP32-S3");
tft.setCursor(60, 80);
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.println("MANDELBROT ART");
delay(1000);
}
void loop() {
if (!ranFractal) {
renderMandelbrot();
ranFractal = true;
delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(36, 106);
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (message[msgIndex] == '\n') {
tft.setCursor(36, tft.getCursorY() + 20);
} else {
tft.print(message[msgIndex]);
}
if (message[msgIndex] != '\0') {
msgIndex++;
} else {
tft.fillRect(36, 106, 220, 60, ILI9341_BLACK);
tft.setCursor(36, 106);
msgIndex = 0;
}
}
}
void renderMandelbrot() {
int w = tft.width();
int h = tft.height();
int maxIter = 15;
for (int py = 0; py < h; py += 2) {
for (int px = 0; px < w; px += 2) {
float x0 = (px - w / 2.0) * 3.5 / w;
float y0 = (py - h / 2.0) * 2.0 / h;
float x = 0.0;
float y = 0.0;
int iteration = 0;
while (x * x + y * y <= 4 && iteration < maxIter) {
float xtemp = x * x - y * y + x0;
y = 2 * x * y + y0;
x = xtemp;
iteration++;
}
uint16_t color = (iteration == maxIter)
? ILI9341_BLACK
: tft.color565(iteration * 16, 255 - iteration * 8, iteration * 6);
tft.fillRect(px, py, 2, 2, color);
}
}
}