I'm having a number of problems during the construction of the matrix LED with 5 MAX7221, now the most serious problem is that with the code I'm using (which I did not write), the scorrimneto is from top to bottom, while should be from right to left, which worked well with another test code found online.
You can reverse the flow by changing the code? because now I mounted the 320 LEDs on a chassis and remove the 5 array to turn them is risky, could cause a short circuit between the LEDs.
this is the code I am using.
Help me please
thanks
//We always have to include the library
//File created for DragonCon 2011
#include "LedControl.h"
#include <Button.h>
// Change these pin numbers as neccessary
char Pin_dataIn = 9; // data in pin
char Pin_clk = 7; // clk pin
char Pin_load = 8; // load pin
char numOfMatrices = 5; // increment this for each 7219 you've got connected. I imagine this will be 5.
int brightness = 8; // set the brightness of the LEDs. Use a value between 0 - 15
char screen[40];
char screenSize = 40;
char textBuffer[3][100];
char textBufferSize[3] = {90,51,66};
int pointer = 0;
long nextFrameTime = 0;
int effectType = 0;
int framePointer = 0;
// init led control object
LedControl lc = LedControl(Pin_dataIn,Pin_clk,Pin_load,numOfMatrices);
Button button = Button(4, HIGH);
/* we always wait a bit between updates of the display */
unsigned int delayTime=40;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
for(int index=0;index<lc.getDeviceCount(); index++) {
lc.shutdown(index,false);
/* Set the brightness to a medium values */
lc.setIntensity(index,brightness);
/* and clear the display */
lc.clearDisplay(index);
}
randomSeed(analogRead(0));
button.setHoldDelay(3000);
loadTextBuffers();
}
void loop() {
button.listen();
if(button.onRelease()) {
effectType++;
if(effectType > 10) {
effectType = 0;
}
pointer = 0;
framePointer = 0;
}
long current = millis();
if(current > nextFrameTime) {
nextFrameTime = current + delayTime;
switch(effectType) {
case 0:
effectThinLine();
break;
case 1:
effectRandomPixels();
break;
case 2:
effectScanner();
break;
case 3:
effectBlinkingEyes();
break;
case 4:
effectTextScroll(0);
break;
case 5:
effectTextScroll(1);
break;
case 6:
effectTextScroll(2);
break;
case 7:
effectArrows();
break;
case 8:
effectECG();
break;
case 9:
effectScannerHorizontal();
break;
default:
effectBlank();
break;
}
display();
}
}
void display() {
unsigned char matrixID = 0;
// screen now holds the updated values
// write to the matrix
for(unsigned char i = 0; i < numOfMatrices; i++) {
for(int j = 0; j < 8; j++) {
int k = j;
k += 1;
if(k > 7) {
k = 0;
}
char matrixID = 4 - i;
//matrixID = 0;
char bufferData = screen[((7-k)+(i*8))];
char rowData = (bufferData >> 1) | (bufferData << 7);
lc.setRow(matrixID,j,rowData);
}
}
/*
for(unsigned char i = 0; i < screenSize; i++) {
matrixID = floor(i/8);
lc.setColumn(matrixID,i,screen[i]);
}
for(unsigned char i = 0; i < numOfMatrices; i++) {
for(unsigned char j = 0; j < 8; j++) {
char matrixID = 4 - i;
//matrixID = 0;
lc.setColumn(matrixID,j,screen[(j+(i*8))]);
}
}
*/
}
void scrollFromRight(int bufferNum) {
int offset = screenSize - pointer;
for(unsigned char i = 0; i < screenSize; i++) {
screen[i] = getBufferData(bufferNum, i-offset);
}
}
void scrollFromLeft(int bufferNum) {
int offset = (0-textBufferSize[bufferNum]) + pointer;
for(unsigned char i = 0; i < screenSize; i++) {
screen[i] = getBufferData(bufferNum, i-offset);
}
}
void staticCenter(int bufferNum) {
int offset = round((screenSize - textBufferSize[bufferNum]) / 2);
for(unsigned char i = 0; i < screenSize; i++) {
screen[i] = getBufferData(bufferNum, i-offset);
}
}
char getBufferData(int bufferNum, int pos) {
char tmp;
if((pos >= 0) && ((pos) < textBufferSize[bufferNum])) {
return textBuffer[bufferNum][pos];
} else {
return B00000000;
}
}
void effectThinLine() {
for(int i = 0; i < 40; i++) {
screen[i] = B00011000;
}
}
void effectRandomPixels() {
for(int i = 0; i < 40; i++) {
screen[i] = random(256);
}
}
void effectScanner() {
for(int i = 0; i < 40; i++) {
screen[i] = B00000000;
}
int tmpPointer = framePointer;
if(framePointer > 37) {
tmpPointer = 37 - (framePointer - 37);
}
for(int i = tmpPointer; i < (tmpPointer+3); i++) {
screen[i] = B11111111;
}
framePointer++;
if(framePointer > 73) {
framePointer = 0;
}
}
void effectScannerHorizontal() {
int tmpPointer = framePointer;
if(framePointer > 6) {
tmpPointer = 6 - (framePointer - 6);
}
for(int i = 0; i < 40; i++) {
screen[i] = B10000000 >> (tmpPointer + 1);
}
display();
delay(50);
framePointer++;
if(framePointer > 11) {
framePointer = 0;
}
}
void effectBlank() {
for(int i = 0; i < 40; i++) {
screen[i] = B00000000;
}
}
void effectTextScroll(char bufferNum) {
pointer += 1;
if(pointer > (textBufferSize[bufferNum] + screenSize)) {
pointer = 0;
}
scrollFromRight(bufferNum);
}
void effectBlinkingEyes() {
if(random(50) == 0) {