I've been working on a project where I'm using a program (LEDMatrixStudio by Paul Freshney) to generate HEX colour code to address WS2812 LEDs in a matrix.
The purpose of this is to create frames of an animated display which I can trigger frame by frame through DMX, I'm trying to structure my code in a way that allows it to act as a framework where all I have to do in order to run a new animation is generate new HEX code and replace the old colour code.
So far this has all been working fine on an individual matrix but now I'm moving towards using an array of tiles and I've hit a roadblock.
What I want to happen: Ideally I'd like to treat my array as if it were a single matrix, as a starting point I'm using 3 8x8 matrices which are arranged in progressive rows.
Where I have for example 3 tiles in series I'd like that to act as 8 rows of 24 pixels rather than 3 tiles of 64. So pixel 0 of Tile 2 should be pixel 8, pixel 0 of Tile 3 should be pixel 16 and so on.
What is actually happening: Using LEDMatrixStudio I'm setting a grid of 24x8, generating the colour code then attempting to display it on an array of 3 8x8 tiles. My code is treating pixel 0 of Tile 2 as pixel 64, pixel 0 of Tile 3 as 128 and so on, this leads to an incorrect display. I can work around this by separating my designs into 8x8 chunks and generating the code for each tile individually but its pretty cumbersome and at some point I'm going to want to make some much larger arrays.
So what am I asking? Is there some function where when x passes beyond the tile width it moves to the adjacent row of the next tile and when x passes the width of the array it moves to the row below? Will this even help given how I'm currently inputting my colour code? Basically is there a better way than what I'm currently doing?
Code I'm using to fill the display;
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>#define PIN 9
/Colour Code*********/
uint32_t ledarray[] = {
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000,
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000,
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00F00000,
0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, 0x00F00000, };/*********initial matrix layout (to get matrix index by x/y)/
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 3, 1, PIN,
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE +
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_RGB + NEO_KHZ800);/*************************************************************************************************/
void setup() {
matrix.begin();
matrix.setBrightness(40);
matrix.show();
}void loop() {
RenderFrame_01();
delay(100);
}void RenderFrame_01()
{
for (int t = 0; t <192 ; t++){
matrix.setPixelColor(t, ledarray[t]);
}
matrix.show();
delay(100);
}
The shape the colour code here represents is a simple red hollow rectangle, I'm aware I could use draw.rectangle instead but in practice the shapes will be more complex images, this is just a shape I use as a test to check everything lines up. This is also a barebones version with the DMX-enabled code removed as I just want to focus on getting the display to work with tile arrangement.
My instinct tells me "> for (int t = 0; t <192 ; t++){ " is where I need to make some changes.
I'm an electrician who messes around with LEDs a lot, my code knowledge isn't great, go easy on me!