wrong leds lit in matrix display - wrong coding? I wrote the following code for displaying a bitmap (small size) on a  LED matrix (formed using APA102 led strip):

//for 24-bit bitmaps

// the header files for the RGB data

 #include &lt;FastLED.h&gt;
 #include "redarray.h"   
 #include "greenarray.h"   //g data header file (hex or dec)
 #include "bluearray.h"   //b data header file (hex or dec)*/

//matrix parameters

#define MatrixWidth 36 //columns
#define MatrixHeight 7 //rows
#define numled (MatrixWidth * MatrixHeight)

//pin details

#define datapin 7

#define clockpin 8

CRGB leds[MatrixWidth * MatrixHeight];

const bool  MatrixSerpentineLayout = true;


 void setup() {

     FastLED.addLeds&lt;APA102, datapin, clockpin&gt;(leds,numled);
     FastLED.clear();
  }

void loop() {


  for(uint8_t x=0 ; x&lt;MatrixWidth ; x++)  {

      for(uint8_t y=0; y &lt; 3; y++) {

            leds[XY (x, y)].setRGB(redarray[x][y],greenarray[x][y],bluearray[x] [y]);

           FastLED.show();

           delay(1);    
         }
      }
   }

      uint16_t XY( uint8_t x, uint8_t y)   
 {
   uint16_t i;

     if( MatrixSerpentineLayout == true) {
       if( y &amp; 0x01) {
        // Odd rows run backwards
          uint8_t reverseX = (MatrixWidth - 1) - x;
          i = (y * MatrixWidth) + reverseX;
     } else {
       // Even rows run forwards
          i = (y * MatrixWidth) + x;
    }
   }

  return i;
}


The following is the data in one of the header files - its of same type for the other two colors.

const unsigned char redarray[36][3] PROGMEM  = {
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x20, 0x20, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x20, 0x20, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x20, 0x20, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 
};

The matrix is in a serpentine form (evident from the XY function in code). I am using an Arduino Due. The problem is that the code compiles and runs...but the bitmap is incorrect. Although I am sure, I am somewhat along the correct path because some LEDs do light up as they should as per the bitmap. But most of them are wrongly lit. 

Could you somebody plz guide where I am going wrong with the coding? I fear there is some mistake in reading the color data from array and allocating it to leds[XY(x,y)].I do not know how a 2D array is read or dealt with by Arduino.

Thanks!
Initialize your arrays like this:

int a[3][4] = {  
   {0, 1, 2, 3} ,   /*  initializers for row indexed by 0 */
   {4, 5, 6, 7} ,   /*  initializers for row indexed by 1 */
   {8, 9, 10, 11}   /*  initializers for row indexed by 2 */
};


...you can read more about it here.

Added later...

The following explanation came from here:

Arrays that are not explicitly divided into rows:

int M[4][5] = {10, 5, -3, 9, 0, 0, 32, 20, 1, 0, 0, 8};


...are filled like this:

int M[4][5] =
{
  {10,  5, -3, 9, 0},
  { 0, 32, 20, 1, 0},
  { 0,  8,  0, 0, 0},
  { 0,  0,  0, 0, 0}
};


As only you understand your data you will have to verify if your data is populating the array as you expect.