passing colour variable to a TFT_ESPI function

I am using TFT_ESPI lib.

I have a Dark and Light themes for my GUI so I want to pass the colour to a function like this:

setTextColor(uint16_t c, uint16_t b)

It will be ok if I do this:

setTextColor(TFT_BLACK, TFT_WHITE)

In the library there are predefined colour like:

#define TFT_BLACK       0x0000      /*   0,   0,   0 */ 
#define TFT_NAVY        0x000F      /*   0,   0, 128 */ 
#define TFT_DARKGREEN   0x03E0      /*   0, 128,   0 */

But what I want is to store a colour in a variable depending on the active theme and then pass it to a function like above.

setTextColor() expects an uint16_t but I have a RGB or Hex.

Which would be the procedure for converting and storing the value in uint16_t variable ?

Read about "RGB color converting into 5:6:5 format" here:

Works great. Thanks

int result = (red << (5 + 6)) | (green << 5) | blue;

This topic was automatically closed after 120 days. New replies are no longer allowed.