Ada hex colours 16bit calculator?

Has anyone ever come across/written a basic calculator (or sketch maybe) that would allow one to enter in 24-bit RGB colour levels like (255,255,255) and have it spit out the respective 4-digit hex number that Adafruit GFX library is used to? e.g. 0xFFFF?

It's not a straight forward linear calculation with the middle 6-bits being for green and the outer two colours 5-bits each.

I'd like to #define a lot more different names than the usual set you find in library examples. Having some thing like the above would so speed this up for experimenting with the shades.

TIA for any pointers or advice!

Jason

The GFX library expects a 16-bit 5-6-5 value.
24-bit RGB is 8-8-8

So you can use the regular color565() method that comes with your TFT library.

uint16_t color565(uint8_t r, uint8_t g, uint8_t b) 
{
    return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3); 
}

or you write a macro that does the same calculation.

David.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.