/*
Forum: https://forum.arduino.cc/t/problem-mit-tft-displays/1441876/30
Wokwi: https://wokwi.com/projects/462736310567641089
2026/04/30
ec2021
Basierend auf dem Adafruit Beispiel (ILI9341-Test)
Demonstriert die online-Umrechnung von RGB 565 Konstanten in BGR mit der Funktion RGB2BGR()
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
// VGA color palette from UTFT-Library
#define VGA_BLACK 0x0000
#define VGA_WHITE 0xFFFF
#define VGA_RED 0xF800
#define VGA_GREEN 0x0400
#define VGA_BLUE 0x001F
#define VGA_SILVER 0xC618
#define VGA_GRAY 0x8410
#define VGA_MAROON 0x8000
#define VGA_YELLOW 0xFFE0
#define VGA_OLIVE 0x8400
#define VGA_LIME 0x07E0
#define VGA_AQUA 0x07FF
#define VGA_TEAL 0x0410
#define VGA_NAVY 0x0010
#define VGA_FUCHSIA 0xF81F
#define VGA_PURPLE 0x8010
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
Serial.begin(9600);
Serial.println("Farbtest RGB versus BGR");
tft.begin();
Serial.println("RGB") ;
testFillScreenRGB();
Serial.println("BGR") ;
testFillScreenBGR();
}
void loop(void) {
}
void testFillScreenRGB() {
yield();
tft.fillScreen(VGA_RED);
yield();
tft.fillScreen(VGA_GREEN);
yield();
tft.fillScreen(VGA_BLUE);
yield();
tft.fillScreen(VGA_BLACK);
yield();
}
void testFillScreenBGR() {
yield();
tft.fillScreen(RGB2BGR(VGA_RED));
yield();
tft.fillScreen(RGB2BGR(VGA_GREEN));
yield();
tft.fillScreen(RGB2BGR(VGA_BLUE));
yield();
tft.fillScreen(VGA_BLACK);
yield();
}
uint16_t RGB2BGR(uint16_t rgb) {
uint16_t r = (rgb >> 11) & 0x1F;
uint16_t g = (rgb & 0x07E0);
uint16_t b = (rgb & 0x1F);
return (b << 11) | g | r;
}
/*
void setColorRGB(byte r, byte g, byte b){
myGLCD.setColor(b,g,r);
}
*/