#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 5
#define TFT_DC 2
#define TFT_RST 4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
String message = " Hello from ESP32 with scrolling text! ";
int scrollX;
void setup() {
tft.begin(10000000);
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextSize(2);
tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK); // text color with background
scrollX = tft.width(); // Start from the right edge
}
void loop() {
tft.fillRect(0, 150, tft.width(), 20, ILI9341_BLACK); // Clear previous text
tft.setCursor(scrollX, 150);
tft.print(message);
scrollX--;
if (scrollX < -(message.length() * 12)) { // 12 = approx char width at textSize 2
scrollX = tft.width(); // reset
}
delay(30); // scroll speed
}