Go Down

Topic: Colors using Adafruit_ST7735.h (Read 170 times) previous topic - next topic

encryptor

I'm trying to fill in the gaps for colors.  I've started with trying to save ORANGE.  I see in Adafruit_ST7735.h ,for lcd display, colors are defined by 0xABCD.  However when I look up colors online I see a 6 digit hex 0xABCDEF.  What am I missing?  How do I define colors using only 4 digit hex, like as seen in Adafruit_ST7735.h file?

Code: [Select]
// Color definitions
#define ST7735_BLACK   0x0000
#define ST7735_BLUE    0xF800
#define ST7735_RED     0x001F
#define ST7735_ORANGE  0x00AA  //TEST CREATING COLOR
#define ST7735_GREEN   0x07E0
#define ST7735_CYAN    0xFFE0
#define ST7735_MAGENTA 0xF81F
#define ST7735_YELLOW  0x07FF
#define ST7735_WHITE   0xFFFF

david_prentice

There is probably a color565(r, g, b) method.
You can write an equivalent macro.

David.

encryptor

There is probably a color565(r, g, b) method.
You can write an equivalent macro.

David.
I don't understand exactly what you're proposing I do.  I need step by step instructions.

david_prentice

You can look up standard 24-bit colours.  i.e. 8-bits for RED, 8-bits for GREEN, ...
You convert them to to 16-bits i.e. 5-bits for RED, 6-bits for GREEN, 5-bits for BLUE:
Code: [Select]

#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3))

#define GREY      RGB(127, 127, 127)
#define DARKGREY  RGB(64, 64, 64)
#define TURQUOISE RGB(0, 128, 128)
#define PINK      RGB(255, 128, 192)
#define OLIVE     RGB(128, 128, 0)
#define PURPLE    RGB(128, 0, 128)
#define AZURE     RGB(0, 128, 255)
#define ORANGE    RGB(255,128,64)


Since this is a common thing to do in TFT programs,   the libraries tend to have suitable methods:
e.g. Adafruit_ST7735.h
Code: [Select]

  uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);

e.g. MCUFRIEND_kbv.h
Code: [Select]

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


David.

encryptor

I tested the 1st block of code and found that it's not RGB, but BGR.  Blue and Green are opposite.  Maybe I should reinstall the library.  I haven't tried color565() yet. 

david_prentice

BGR is a single bit to change.   Your library proably has a configuration option.

Of course you could change the macro but the whole world expects RED to be 0xF800.

Go Up