Better number conversion

I am working on an art project. Using processing it takes the video input, blurs it a bit, and converts the video into an 8x8 grid. The column, row, red component, blue component, and green component are then sent to the Ardunio. The Arduino then reads these values does some math and using the RGB Matrix library, it colors an RGB LED with the color from processing. I have it working, but the colors are off.

Here’s the problem. Processing sends 3 numbers. Red: 0 - 255, Green: 0 - 255, and Blue: 0 - 255. But the way the library is set up, it only accepts one number from 0 - 255. The library breaks down the number using binary. In binary, 255 which is the max as 11111111. The first 3 digits represents the red component, second 3 digits are the blue component, and the last 2 represent the blue.

Here is how I am doing the conversion in Ardunio:

``````    int r = red_val/32; //64
int g = green_val/32; //64
int b = blue_val/64; //128

final_val=(r<<5)+(g<<2)+b; // red moves 5 bits to the left, green 2, and blue stays

RGBMatrix.fillPixel(0, row, col, final_val);
``````

Like I said, it works. But the colors do no match. I took it one step further and graphed the 2 values in Excel. It clearly shows the values decreasing, but my blue completely disappears. I can not think of a better way to convert this number over. I was hoping for some ideas. Thanks.

You might be getting bitten by signed/unsigned number conversions, and use of ‘+’ instead of ‘|’.

See if this makes a difference:

``````uint8_t r = ((uint8_t)red_val >> 5) & 0x07;
uint8_t g = ((uint8_t)green_val >> 5) & 0x07;
uint8_t b = ((uint8_t)blue_val >> 6) & 0x03;

final_val=(r<<5) | (g<<2) | b; // red moves 5 bits to the left, green 2, and blue stays

RGBMatrix.fillPixel(0, row, col, final_val);
``````

The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

That helped produce much better white's. It's still not where I want it to be. Thanks for the input.

the colors do not match.

You might have to do some "pre-processing" to get a low-res RGB LED matrix to come close to matching the colors of a video monitor. The pixels in your monitor are carefully balanced so that equal values of R, G, and B will give you assorted shades of gray, and standard ratios will give you standard looking colors (it's "calibrated") The LED matrix probably has the brightest possible red, green, and blue LEDs without a lot of attention paid to accurate color reproduction.