ArduinoLilyGo T-DisplayLab virtual

T-Display hello

LilyGo’s T-Display with Adafruit_ST7789: its 135x240 screen, a counter and colours.

T-Display hello in Argynix Lab

The code

sketch.inoC++
// LilyGo's T-Display: an ST7789 135x240 on SPI pins of its own (SCK 18, MOSI 19, CS 5,
// D/C 16, RST 23) and its backlight on 4. Adafruit_ST7789 drives it.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>

#define TFT_CS 5
#define TFT_DC 16
#define TFT_RST 23
#define TFT_BL 4

Adafruit_ST7789 tft(TFT_CS, TFT_DC, TFT_RST);
const uint16_t colours[] = {ST77XX_RED, ST77XX_GREEN, ST77XX_BLUE, ST77XX_YELLOW, ST77XX_MAGENTA};
int n = 0;

void setup() {
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);
  SPI.begin(18, -1, 19, TFT_CS);
  tft.init(135, 240);
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRect(0, 0, 135, 40, ST77XX_BLUE);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(2);
  tft.setCursor(10, 12);
  tft.print("T-Display");
}

void loop() {
  tft.fillRect(10, 60, 115, 40, ST77XX_BLACK);
  tft.setCursor(10, 66);
  tft.setTextSize(4);
  tft.print(n);
  tft.fillRect(10, 120, 115, 100, colours[n % 5]);
  n++;
  delay(500);
}