Display — Colors
M5GFX source:
lgfx/v1/LGFXBase.hpp
Back to: Display overview
Color constants, conversion functions, and the current drawing color.
Named Colors
Global constants available via <M5GFX.h>:
TFT_BLACK TFT_NAVY TFT_DARKGREEN TFT_DARKCYAN
TFT_MAROON TFT_PURPLE TFT_OLIVE TFT_LIGHTGREY
TFT_DARKGREY TFT_BLUE TFT_GREEN TFT_CYAN
TFT_RED TFT_MAGENTA TFT_YELLOW TFT_WHITE
TFT_ORANGE TFT_GREENYELLOW TFT_PINK TFT_BROWN
TFT_GOLD TFT_SILVER TFT_SKYBLUE TFT_VIOLET
Shorthand: BLACK, WHITE, RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA.
M5Cardputer.Display.fillScreen(TFT_BLACK);
M5Cardputer.Display.fillRect(10, 10, 50, 50, TFT_RED);
M5Cardputer.Display.drawString("OK", 10, 70);
color565()
Converts 8-bit RGB components to a 16-bit packed color (RGB565).
| Parameter | Type | Range | Description |
|---|---|---|---|
r |
uint8_t |
0–255 | Red component |
g |
uint8_t |
0–255 | Green component |
b |
uint8_t |
0–255 | Blue component |
| Return | Description |
|---|---|
uint16_t |
16-bit packed 5-6-5 format |
uint16_t orange = M5Cardputer.Display.color565(255, 165, 0);
M5Cardputer.Display.fillScreen(orange);
color888()
Converts 8-bit RGB to 32-bit packed color (RGB888).
| Parameter | Type | Range | Description |
|---|---|---|---|
r |
uint8_t |
0–255 | Red |
g |
uint8_t |
0–255 | Green |
b |
uint8_t |
0–255 | Blue |
| Return | Description |
|---|---|
uint32_t |
32-bit packed 8-8-8 format |
setColor() — RGB
Sets the current drawing color from RGB components. All subsequent drawing operations use this color.
| Parameter | Type | Range | Description |
|---|---|---|---|
r |
uint8_t |
0–255 | Red |
g |
uint8_t |
0–255 | Green |
b |
uint8_t |
0–255 | Blue |
setColor() — Packed
Sets the current drawing color from a packed color value.
| Parameter | Type | Description |
|---|---|---|
color |
uint16_t |
16-bit packed color (RGB565) |
M5Cardputer.Display.setColor(TFT_CYAN);
M5Cardputer.Display.drawCircle(160, 120, 50);
// Custom packed color
M5Cardputer.Display.setColor(M5Cardputer.Display.color565(200, 100, 50));
setBaseColor()
Sets the background color used by fillScreen() when called without arguments, or by clear().
M5Cardputer.Display.setBaseColor(TFT_NAVY);
M5Cardputer.Display.fillScreen(); // Fills with TFT_NAVY
getRawColor()
Returns the current drawing color in raw format.
getColorDepth()
Returns the current color depth (bits per pixel). For M5Cardputer this is typically 16.