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 <FastLED.h>
#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<APA102, datapin, clockpin>(leds,numled);
FastLED.clear();
}
void loop() {
for(uint8_t x=0 ; x<MatrixWidth ; x++) {
for(uint8_t y=0; y < 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 & 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!