I have a 16x16 matrix, and I want to control each LED in the matrix, giving it RGB values and brightness to determine its illumination. I'm using matrix_16_data to input the data using an array mentioned in the code.
When I have 128 data points, it works, meaning the code functions properly in this format:
#include <Adafruit_NeoPixel.h>
#define MATRIX_M1_PIN 7 // Matrix 16*16
Adafruit_NeoPixel matrix_16 = Adafruit_NeoPixel(256, MATRIX_M1_PIN, NEO_GRB + NEO_KHZ800);
uint8_t brightness = 0;
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
void setup() {
matrix_16.begin();
matrix_16.show();
}
void loop() {
uint8_t matrix_16_data[][4] = {
{255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5},
{0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10},
{255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50}
};
for (int i = 0; i < 128; i++) {
int row = i / 16; // Calculate the row (0-15)
int col;
if (row % 2 == 0) {
col = i % 16; // Even rows
} else {
col = 15 - (i % 16); // Odd rows
}
int matrixIndex = row * 16 + col;
red = matrix_16_data[i][0];
green = matrix_16_data[i][1];
blue = matrix_16_data[i][2];
brightness = matrix_16_data[i][3];
if (brightness == '-') {
brightness = 10;
red = 0;
green = 0;
blue = 0;
}
if (row % 2 == 0) {
matrix_16.setPixelColor((row) * 16 + (15-col), brightness * red / 255, brightness * green / 255, brightness * blue / 255);
} else {
matrix_16.setPixelColor((row) * 16 +(15-col), brightness * red / 255, brightness * green / 255, brightness * blue / 255);
}
// delay(100);
}
matrix_16.show();
}
But it doesn't work in this format:
#include <Adafruit_NeoPixel.h>
#define MATRIX_M1_PIN 7 // Matrix 16*16
Adafruit_NeoPixel matrix_16 = Adafruit_NeoPixel(256, MATRIX_M1_PIN, NEO_GRB + NEO_KHZ800);
uint8_t brightness = 0;
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
void setup() {
matrix_16.begin();
matrix_16.show();
}
void loop() {
uint8_t matrix_16_data[][4] = {
{255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5},
{0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10},
{255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5}, {255, 255, 0,5},
{0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10}, {0, 176, 240,10},
{255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {112, 48, 160,3}, {255, 255, 255,'-'},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50},
{255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 255,'-'}, {255, 255, 0,50}
};
for (int i = 0; i < 256; i++) {
int row = i / 16; // Calculate the row (0-15)
int col;
if (row % 2 == 0) {
col = i % 16; // Even rows
} else {
col = 15 - (i % 16); // Odd rows
}
int matrixIndex = row * 16 + col;
red = matrix_16_data[i][0];
green = matrix_16_data[i][1];
blue = matrix_16_data[i][2];
brightness = matrix_16_data[i][3];
if (brightness == '-') {
brightness = 10;
red = 0;
green = 0;
blue = 0;
}
if (row % 2 == 0) {
matrix_16.setPixelColor((row) * 16 + (15-col), brightness * red / 255, brightness * green / 255, brightness * blue / 255);
} else {
matrix_16.setPixelColor((row) * 16 +(15-col), brightness * red / 255, brightness * green / 255, brightness * blue / 255);
}
// delay(100);
}
matrix_16.show();
}
I want it to work like in the second example, and I can't find the mistake. When I have a '-', it should refer to an LED that needs to be turned off.
I'm having trouble understanding the logic behind this. I would appreciate some assistance!







