Better way to transform values?
in
Programming Questions
•
2 years ago
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:
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:
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.
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);
1