Hi,
I built a 16x16 Matrix divided into 4 8x8 matrices when controlling it with my code, it somtimes stops working I think it run out of memory:
An example (configuration.h is included in them main programm):
/********************************************************/
/* */
/* This file is used to adapt the following: */
/* -pins your matrices are connected to */
/* -total number of matrices */
/* */
/* advanced option: */
/* -how you matrices are conneted to the */
/* 74HC595 */
/* */
/********************************************************/
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 6;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 7;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 5;
//Total number of matrices
const int totalNumberOfMatrices = 4;
//By changing byte - values you can adapt the way how your matrice is connected
//Bytes might need to be added or subtracted when more or less matrices are used
const int bytesX[totalNumberOfMatrices][8] = { {127, 191, 223, 239, 247, 251, 253, 254},
{127, 191, 223, 239, 247, 251, 253, 254},
{254, 253, 251, 247, 239, 223, 191, 127},
{254, 253, 251, 247, 239, 223, 191, 127},
};
const int bytesY[totalNumberOfMatrices][8] = { {128, 64, 32, 16, 8, 4, 2, 1},
{ 1, 2, 4, 8, 16, 32, 64, 128},
{128, 64, 32, 16, 8, 4, 2, 1},
{ 1, 2, 4, 8, 16, 32, 64, 128},
};
/* Size of Matrices supported is momentary limited to 8*8
Please do not change these values as the programm may not work correctly afterwards */
const int height = 8;
const int width = 8;
Main Programm:
// Start main programm
#include "configuration.h" // cointains information about how the matrices are built / connected
enum coordinates { x, y };
void lightUpLeds(int drawLeds[][64][2], int length);
void createFigure(int which, int bottomLeftCornerX, int bottomLeftCornerY);
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
int drawLeds[totalNumberOfMatrices][height*width][2] = {0};
// Left Eye
drawLeds[1][0][x] = 3;
drawLeds[1][0][y] = 4;
drawLeds[1][1][x] = 3;
drawLeds[1][1][y] = 3;
drawLeds[1][2][x] = 4;
drawLeds[1][2][y] = 8;
drawLeds[1][3][x] = 4;
drawLeds[1][3][y] = 7;
drawLeds[1][4][x] = 4;
drawLeds[1][4][y] = 6;
drawLeds[1][5][x] = 4;
drawLeds[1][5][y] = 5;
drawLeds[1][6][x] = 4;
drawLeds[1][6][y] = 3;
drawLeds[1][7][x] = 5;
drawLeds[1][7][y] = 3;
drawLeds[1][8][x] = 6;
drawLeds[1][8][y] = 3;
drawLeds[1][9][x] = 7;
drawLeds[1][9][y] = 3;
drawLeds[1][10][x] = 8;
drawLeds[1][10][y] = 3;
drawLeds[3][0][x] = 4;
drawLeds[3][0][y] = 4;
drawLeds[3][1][x] = 4;
drawLeds[3][1][y] = 3;
////---------------------------------------------------------------------------------------
////---------------------------------------------------------------------------------------
//// When adding these two lines it stops working
/* drawLeds[3][2][x] = 4;
drawLeds[3][2][y] = 2;*/
////---------------------------------------------------------------------------------------
////---------------------------------------------------------------------------------------
lightUpLeds(drawLeds, 1000000);
}
And finnaly the function
// Start ligtUpLeds function
void lightUpLeds(int drawLeds[][height*width][2], int length){
/*** ***/
/*** no support for non quadratic matrices(momentary only 8*8) ***/
/*** ***/
int time = 400;
/**** Variable to count number of y values ****/
int relativizelength = 0;
/**** Variable to save if the outshifting process has to be skiped or not ****/
int skip = 0;
/**** Variables to calculate ****/
int dataX[totalNumberOfMatrices][width][height]; // x- Values per y value
for(int a=0; a < totalNumberOfMatrices; a++)
for(int a2=0; a2 < 8; a2++)
for(int a3= 0; a3 < 8; a3++)
dataX[a][a2][a3] = 255;
int dataOutput[totalNumberOfMatrices][2][8] = {0}; // final 8 x- and y-values
/**** Checking the array for values ****/
for(int matrixNumber = 0; matrixNumber < totalNumberOfMatrices; matrixNumber++)
for(int possibleLed = 0; possibleLed < width*height; possibleLed++)
for(int row = 0; row < 8; row++){
/**** iterate y values ****/
if((drawLeds[matrixNumber][possibleLed][y]) == (row+1) )
dataOutput[matrixNumber][y][row] = bytesY[matrixNumber][row];
/**** iterate x values ****/
if(drawLeds[matrixNumber][possibleLed][x] == (row+1) )
dataX[matrixNumber][drawLeds[matrixNumber][possibleLed][y]-1][row] = bytesX[matrixNumber][row];
}
/**** adapting the length of the action to the numbers of y values to light up ****/
for(int b = 0; b < height; b++)
for(int matrixNumber = 0; matrixNumber < totalNumberOfMatrices; matrixNumber++)
if(dataOutput[matrixNumber][y][b] != 0 ){ relativizelength++; break;}
length /= relativizelength;
/**** Calculating final x-Output ****/
for(int matrixNumber = 0; matrixNumber < totalNumberOfMatrices; matrixNumber++)
for(int u = 0; u < 8; u++ ){
dataOutput[matrixNumber][x][u] = dataX[matrixNumber][u][7];
for(int u2 = 0; u2 < width-1; u2++)
dataOutput[matrixNumber][x][u] += dataX[matrixNumber][u][u2];
dataOutput[matrixNumber][x][u] -= 255*(width-1);
}
for(int repeat = 0; repeat < length - (length*relativizelength/1000)*40* totalNumberOfMatrices ; repeat++){
/*if(time > 200)
time -= 100;
else if(time > 100)
time -= 50;
else if(time > 20)
time -= 10;
else if(time > 1)
time = 1;
*/
if(time - time *0.1 > 1)
time -= time *0.1;
else
time = 1;
/**** - ((length*relativizelength)/1000)* (61* totalNumberOfMatrices)) : approximate conversion factor to get the right light on time when consindering computation time of Arduino****/
for(int u = 0; u < 8; u++ ){
for(int matrixNumber = 0; matrixNumber < totalNumberOfMatrices; matrixNumber++)
if(dataOutput[matrixNumber][y][u] != 0) skip++;
if(skip != 0){
skip = 0;
/**** Making the LEDs shine after checking if they have to light up ****/
digitalWrite(latchPin, LOW);
for(int matrixToDisplay = (totalNumberOfMatrices-1); matrixToDisplay > -1; matrixToDisplay--){
if(matrixToDisplay % 2 == 0){
shiftOut(dataPin, clockPin, MSBFIRST, dataOutput[matrixToDisplay][x][u]);
shiftOut(dataPin, clockPin, MSBFIRST, dataOutput[matrixToDisplay][y][u]);
}else{
shiftOut(dataPin, clockPin, MSBFIRST, dataOutput[matrixToDisplay][y][u]);
shiftOut(dataPin, clockPin, MSBFIRST, dataOutput[matrixToDisplay][x][u]);
}
}
digitalWrite(latchPin, HIGH);
delay(time);
}
}
}
}
The issues occurs when adding the two marked lines, same issue occurs when trying to print a line while the lightUpLeds function is looping througth the "Making the LED shine loop".
Is there any better way to controll the 16x16 matrix(connected with 8 595er), to make the programm perform better? For example not using so many 3 dimensional arrays
In general you specify which LED you want to make shine(using x and y coordinates) and then the programm calculates the output bytes.