#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

// Pin configuration for ILI9341 on ESP32
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4

// Create ILI9341 object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  Serial.begin(115200);

  // Initialize ILI9341 display
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(2);
  tft.setTextColor(ILI9341_WHITE);

  Serial.println("ILI9341 initialized successfully.");
}

void loop() {
  // Display text on ILI9341
  tft.setCursor(10, 10);
  tft.print("Hello, ESP32!");

  delay(2000); // Delay for 2 seconds
  tft.fillScreen(ILI9341_BLACK); // Clear the screen

  delay(1000); // Delay for 1 second before repeating
}