0

RGB Matrix Graphics
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RGB Matrix Graphics

by adamr1 on Mon Oct 09, 2017 9:39 pm

Hello. I am working on a project using the 3mm 64x32 LED matrix. I am using a tool I found online called LED Matrix Studio. I am trying to covert a BMP to be displayed on the matrix (in color). This tool exports the pixel info into an array like:
Code: Select all | TOGGLE FULL SIZE
 uint32_t ledarray[]= {
0xFFFFFF00, 0x62858100, 0xCAD1EE00..... }
 


My plan was to loop through data to display each pixel.

Is there a way to display this information using the matrix?

Thank you.

adamr1
 
Posts: 117
Joined: Sun Jun 02, 2013 8:24 am

Re: RGB Matrix Graphics

by adafruit_support_rick on Tue Oct 10, 2017 12:57 pm

Sure. You copy and paste that array to your sketch.

Go into a loop and call matrix.drawPixel(x, y, matrix.Color888(r, g, b)); with the data from the array.
Something like this
Code: Select all | TOGGLE FULL SIZE
  uint8_t *arrayPtr = (uint8_t)ledarray;
  for (int x=0; x < 64; x++)
  {
    for (int y=0; y < 32; y++)
    {
        uint8_t r = *arrayPtr++;
        uint8_t g = *arrayPtr++;
        uint8_t b = *arrayPtr++;
        matrix.drawPixel(x, y, matrix.Color888(r, g, b));
        arrayPtr++;  //skip 4th byte
    }
  }


Now, the above is just an outline of the general procedure. I don't know the color order or the array x,y order in the array data, so you may have to adjust the above code to get it right.

adafruit_support_rick
 
Posts: 34871
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Matrix Graphics

by adamr1 on Tue Oct 10, 2017 1:13 pm

Thanks for the reply. This makes sense but I just don't see how the r g b info is extracted to use in with the color888 function.

adamr1
 
Posts: 117
Joined: Sun Jun 02, 2013 8:24 am

Re: RGB Matrix Graphics

by adafruit_support_rick on Tue Oct 10, 2017 1:29 pm

ledarray is a pointer to a uint32_t. I'm casting it to a pointer to a uint8_t. So, that means that the uint8_t pointer will access the four bytes of the uint32_t in order.

Code: Select all | TOGGLE FULL SIZE
        uint8_t r = *arrayPtr++;  //gets the first byte of the uint32_t, and increments the uint8_t pointer
        uint8_t g = *arrayPtr++;  //gets the second byte of the uint32_t, and increments the uint8_t pointer
        uint8_t b = *arrayPtr++;  //gets the third byte of the uint32_t, and increments the uint8_t pointer

adafruit_support_rick
 
Posts: 34871
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: RGB Matrix Graphics

by adamr1 on Tue Oct 10, 2017 8:49 pm

Thanks, I get an error:
cast from 'const uint32_t* {aka const long unsigned int*}' to 'uint8_t {aka unsigned char}' loses precision

on the line
Code: Select all | TOGGLE FULL SIZE
uint8_t *arrayPtr = (uint8_t)ledarray;


Any ideas?

Thank you!

adamr1
 
Posts: 117
Joined: Sun Jun 02, 2013 8:24 am

Re: RGB Matrix Graphics

by adafruit_support_rick on Wed Oct 11, 2017 12:18 pm

D'Oh! Sorry. Typo. Should be casting to a (uint8_t*). Also, there's another typo in there - it should be *arrayPtr++; to skip the fourth byte


While I was looking at this, I realized that the array you're getting is assuming a different byte order for uint32_t than is used by the Arduino (if you're interested, look up the difference between "little-endian" and "big-endian")

Anyway, it means that you have to reverse the order of reading the bytes. The first byte you see will be the 00 that you want to ignore. The next byte will be blue, then green, then red:
Code: Select all | TOGGLE FULL SIZE
  uint8_t *arrayPtr = (uint8_t*)ledarray;
  for (int x=0; x < 64; x++)
  {
    for (int y=0; y < 32; y++)
    {
        *arrayPtr++;  //skip 1st byte
        uint8_t b = *arrayPtr++;  //blue is second byte
        uint8_t g = *arrayPtr++;  //green is third byte
        uint8_t r = *arrayPtr++;  //red is fourth byte
        matrix.drawPixel(x, y, matrix.Color888(r, g, b));
    }
  }

adafruit_support_rick
 
Posts: 34871
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.