Display Test
DisplayTest.ino
tests the display and the brightness control. After initialization, the screen is filled with different colors. Then, the brightness increases step by step from 0 to the maximum and back to 0 while printing the brightness value on the screen.
#include <Adafruit_GFX.h> // Core graphics library#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789#include <SPI.h>
#define LCD_DC 1#define LCD_CS 2#define LCD_BL 3#define LCD_RST -1
#define SPI_MOSI 11#define SPI_SCK 12#define SPI_MISO 13
Adafruit_ST7789 lcd = Adafruit_ST7789(LCD_CS, LCD_DC, LCD_RST);
void setup() { Serial.begin(115200); SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI, LCD_CS);
lcd.init(240, 240); lcd.setRotation(1);
pinMode(LCD_BL, OUTPUT);
Serial.println("STARTED");}
void loop() { lcd.fillScreen(ST77XX_WHITE); lcd.setTextColor(ST77XX_BLACK);
analogWrite(LCD_BL, 127);
lcd.fillScreen(ST77XX_BLACK); delay(1000); lcd.fillScreen(ST77XX_RED); delay(1000); lcd.fillScreen(ST77XX_GREEN); delay(1000); lcd.fillScreen(ST77XX_BLUE); delay(1000); lcd.fillScreen(ST77XX_WHITE); delay(1000);
lcd.fillScreen(ST77XX_BLACK); delay(3000);
lcd.setCursor(0,0); lcd.print("Brightness:");
analogWrite(LCD_BL, 0); lcd.fillScreen(ST77XX_WHITE);
for(int i=0; i<256 ; i+=2){ analogWrite(LCD_BL, i); lcd.print(";" + String(i)); delay(25); }
for(int i=255; i>=0 ; i-=2){ analogWrite(LCD_BL, i); lcd.print(";" + String(i)); delay(25); }
delay(3000);}