#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// Display Pins
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 13
#define TFT_MISO 12
#define TFT_SCK 14
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
//RGB LED Pins
#define LED_R 4
#define LED_G 16
#define LED_B 17
// function to determine color
void setRGB(bool r, bool g, bool b) {
digitalWrite(LED_R, r ? LOW : HIGH);
digitalWrite(LED_G, g ? LOW : HIGH);
digitalWrite(LED_B, b ? LOW : HIGH);
}
void setup() {
SPI.begin(TFT_SCK, TFT_MISO, TFT_MOSI, TFT_CS);
tft.begin();
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
setRGB(false, false, false);
tft.setCursor(20, 120);
// Set text color and size
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
// Print first message
tft.println("Hello ESP32");
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
}
void loop() {
// Array of messages to display
const char* messages[] = {
"Hello ESP32",
"I love Wokwi!",
"ESP32-2432S028R"
};
// Corresponding RGB colors for each message
const bool colors[][3] = {
{true, false, false}, // Red
{false, true, false}, // Green
{false, false, true} // Blue
};
for (int i = 0; i < 3; i++) {
// Set LED color
setRGB(colors[i][0], colors[i][1], colors[i][2]);
// Clear previous text area (black rectangle)
tft.fillRect(20, 160, 200, 30, ILI9341_BLACK);
// Set cursor to print new message
tft.setCursor(20, 160);
// Print message on screen
tft.println(messages[i]);
// Wait 1 second before next message
delay(1000);
}
}