Hello all,
I have an RGB lcd that displays 16 bit colour such as 0xffff (White), 0x001f (Blue), does anyone know of an easy-ish way to control the individual RGB componants of each colour, the 16 bit colour format is as follows
0b1111100000000000 (5 bits for red)
0b0000011111100000 (6 bits for green)
0b0000000000011111 (5 bits for Blue)
the bit shifting comes into it when i want to take a value of red and << it into the right position something like
int RED = 63; //Full Red
int COLOUR = RED << 11
but i know this isn't right, also green having 6 bits complicates things
also should Colour be a long variable as it is a 16 bit number.
Im not asking for any freebies, just a few pointers would be very helpfull, the display uses the HX8347 chip, so far i haven't found an arduino library to use this and have resorted to writing my own with code intended for 8051 uc's.
struct rgb_t
{
union
{
unsigned short _r:5, _g:6, _b:5;
unsigned short _rgb;
};
};
void HX8347::clearBG(int red, int green, int blue)
{
address_set(0, 0, 239, 319);
rgb_t rgb;
rgb._r = red;
rgb._g = green;
rgb._b = blue;
for ( int i = 0; i < 320; i++ )
{
for ( int j = 0; j < 240; j++ )
{
main_Write_DATA(rgb._rgb);
}
}
}
Or alternately you should be able to use -
struct rgb_t
{
union
{
unsigned short _r:5, _g:6, _b:5;
unsigned short _rgb;
};
rgb_t(unsigned short r, unsigned short g, unsigned short b)
: _r(r) _g(g) _b(b)
{}
};
void HX8347::clearBG(int red, int green, int blue)
{
address_set(0, 0, 239, 319);
rgb_t rgb(red, green, blue);
for ( int i = 0; i < 320; i++ )
{
for ( int j = 0; j < 240; j++ )
{
main_Write_DATA(rgb._rgb);
}
}
}