ArduinoESP32 DevKit V1Lab virtual

Colour TFT (ILI9341)

Adafruit_ILI9341 on the ESP32’s SPI: a title, a counter and a bar that grows.

Colour TFT (ILI9341) in Argynix Lab

The code

sketch.inoC++
// A 2.4-inch ILI9341 colour TFT on the ESP32's SPI bus (VSPI: SCK 18, MOSI 23,
// MISO 19), drawn with Adafruit_GFX: text, rectangles, colours.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#define TFT_CS 5
#define TFT_DC 4
#define TFT_RST 15

Adafruit_ILI9341 tft(TFT_CS, TFT_DC, TFT_RST);
int count = 0;

void setup() {
  Serial.begin(115200);
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  tft.fillRect(0, 0, 320, 40, ILI9341_NAVY);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.setCursor(12, 12);
  tft.print("Argynix Lab TFT");
  tft.drawRect(10, 180, 300, 30, ILI9341_WHITE);
  Serial.println("Screen ready");
}

void loop() {
  tft.fillRect(10, 70, 300, 60, ILI9341_BLACK);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(5);
  tft.setCursor(20, 80);
  tft.print(count);
  int width = map(count % 50, 0, 49, 0, 296);
  tft.fillRect(12, 182, width, 26, count % 100 < 50 ? ILI9341_GREEN : ILI9341_ORANGE);
  if (count % 50 == 49) tft.fillRect(12, 182, 296, 26, ILI9341_BLACK);
  count++;
  delay(100);
}