I'm using a SSD1331 RGB OLED Display such as this one.
In the example code, the colors are preset using 4-digit hex code like this:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
How do I use a 6-digit hex code for the color instead of 4-digit? Is it possible? Do I need a different library instead of the Adafruit GFX one? Thanks!
/*!
@brief Given 8-bit red, green and blue values, return a 'packed'
16-bit color value in '565' RGB format (5 bits red, 6 bits
green, 5 bits blue). This is just a mathematical operation,
no hardware is touched.
@param red 8-bit red brightnesss (0 = off, 255 = max).
@param green 8-bit green brightnesss (0 = off, 255 = max).
@param blue 8-bit blue brightnesss (0 = off, 255 = max).
@return 'Packed' 16-bit color value (565 format).
*/
uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
}
The arguments are individual 8-bit R, G, B.
You would extract each 8-bit field from your 24-bit "6-digit hex"
Adafruit_SPITFT class gets built whenever you inherit from Adafruit_GFX.
Most third party libraries will inherit graphics from Adafruit_GFX. But they will probably avoid the mash-up that is Adafruit_SPITFT. Hence they include their own color565(r, g, b) method.