uint32_t rgb shifting

I'm using the rainbowduino and it has some methods that take individual r g b values as unsigned chars, and some that take a 24bit rgb colour code.

I want to convert r g b values into this 24bit colour code of type uint32_t (so that all my code only has to use r g b values).

When passing the uint32_t methods 0xFF0000 I get red, 0x00FF00 green, and 0x0000FF blue. but if i try r<<16 + g<<8 + b, it does not work

Any ideas?

Rb.setPixelXY(unsigned char x, unsigned char y, unsigned char colorR, unsigned char colorG, unsigned char colorB)
This sets the pixel(x,y)by specifying each channel(color) with 8bit number.

Rb.setPixelXY(unsigned char x, unsigned char y, unit32_t colorRGB)
This sets the pixel(x,y)by specifying a 24bit RGB color code.

but if i try r<<16 + g<<8 + b

 ((long) r<<16) + ((long)g<<8) + b

(long)r<<16 etc did not work :frowning:

using this method, r = 100, g =200, b =0 gave green, but r=0, g=200, b=0 gave nothing

How are r, g, and b defined? How is the value that the shifted data is stored in defined? In other words, where is your code?

AWOL:

but if i try r<<16 + g<<8 + b

 ((long) r<<16) + ((long)g<<8) + b

You probably meant unsigned long.

Anyway, since we started with bitwise operations, why don't just make a bitwise or (with casting)?

// color is a uint32_t
color = (uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b;