Multiple MAX 7219/7221 for "Christmas card" by Thomas123 in the old forum!

Hello All!

I'm back with a new question: how can I increase the number of MAX7219 in the "Chrismas card" project posted by Thomas123 (Congratulations!!!) in the old forum? I want to use 4 MAX7219/7221 with 4 LED matrix in line, transition from right to left. What I need to change in the original code?

Link for "Christmas card": http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290449670

Thanks in advance!

Nobody?

In regard to driving multiple MAX72xx, have you looked at this ?
http://arduino.cc/playground/Main/LedControl

Hi all,
maybe I can help a little bit. I also took the "Christmas card" example, created by Thomas123, which is a good thing to start from.
So if you want to use 2,3 oder more Max7219 you have to casacade the hardware first.
Then the software has to tell each single Max7219 what to do.
Hardware 8x8 Matrix = Kingbright TC23-11EWA. I put the pinout into the attachment.

Example 1 (2 Max7219) :
Draws lines on rows / columns and some pixels across 2 cascaded Max7219.

Example 2 (4 Max7219):
Draws a sprite and moves it across 4 Max7219/8x8 Matrix

If you try to use it check the pins first
Maybe you will have to swicht/exchange "setColumn" against "setRow" and vice versa ... depending on your hardware.

-EXAMPLE 1---------------------------

#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn Max7219 Pin 1
pin 11 is connected to the CLK Max7219 Pin 13
pin 10 is connected to LOAD Max7219 Pin 12
We have only a two MAX72XX.
*/
int Pin11 = 11;
int Pin12 = 12;
int Pin13 = 13;
int Number_of_Max = 2;

LedControl lc=LedControl(Pin11,Pin13,Pin12,Number_of_Max);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

void setup() {
/*The MAX72XX are in power-saving mode on startup, we have to do a wakeup call /
lc.shutdown(0,false);
lc.shutdown(1,false);
/
Set the brightness to a certain values /
lc.setIntensity(0,15);
lc.setIntensity(1,15);
/
and clear the displays */
lc.clearDisplay(0);
lc.clearDisplay(1);
}

void writeRowsOnMatrix() {
int a;

for (a = 0; a < 16; a++) {
if (a < 8) // 1. Max7219
{
lc.setRow(0,a,255); // switch LEDs on
delay(delaytime);
lc.setRow(0,a,0); // switch LEDs off
}
if (a >= 8) // 2. Max7219
{
lc.setRow(1,a-8,255); // switch LEDs on
delay(delaytime);
lc.setRow(1,a-8,0); // switch LEDs off
}
}
}

void writeColsOnMatrix() {
int b;

for (b = 0; b < 8; b++) {
lc.setColumn(0,b,255); // 1. Max7219 switch LEDs on
lc.setColumn(1,b,255); // 2. Max7219 switch LEDs on
delay(delaytime);
lc.setColumn(0,b,0); // 1. Max7219 switch LEDs off
lc.setColumn(1,b,0); // 2. Max7219 switch LEDs off
delay(delaytime);
}
}

void writeRowsBackwardsOnMatrix() {
int c;

for (c = 15; c >-1; c--) {
if (c < 8) // 1. Max7219
{
lc.setRow(0,c,255); // switch LEDs on
delay(delaytime);
lc.setRow(0,c,0); // switch LEDs off
}
if (c >= 8) // 2. Max7219
{
lc.setRow(1,c-8,255); // switch LEDs on
delay(delaytime);
lc.setRow(1,c-8,0); // switch LEDs off
}
}
}

void writeColsBackwardsOnMatrix() {
int b;

for (b = 7; b > -1; b--) {
lc.setColumn(0,b,255); // 1. Max7219 switch LEDs on
lc.setColumn(1,b,255); // 2. Max7219 switch LEDs on
delay(delaytime);
lc.setColumn(0,b,0); // 1. Max7219 switch LEDs off
lc.setColumn(1,b,0); // 2. Max7219 switch LEDs off
delay(delaytime);
}
}

void writePixelsOnMatrix() {
int x_row0;
int y_col0;

int x_row1;
int y_col1;

int z; //Number of loops

for (z = 0; z < 20; z++) {
x_row0 = random(0,7);
y_col0 = random(0,7);
x_row1 = random(0,7);
y_col1 = random(0,7);
lc.setLed(0,x_row0,y_col0,true); //switch on random pixel for 1. Max7219
lc.setLed(1,x_row1,y_col1,true); //switch on random pixel for 2. Max7219
delay(delaytime);
lc.setLed(0,x_row0,y_col0,false); //switch off random pixel off 1. Max7219
lc.setLed(1,x_row1,y_col1,false); //switch off random pixel off 2. Max7219
}
}

void loop() {
writeRowsOnMatrix();
writeColsOnMatrix();
writePixelsOnMatrix();
writeRowsBackwardsOnMatrix();
writeColsBackwardsOnMatrix();
writePixelsOnMatrix();
}

-EXAMPLE 2 ---------------------------

#include "LedControl.h"
#include <avr/pgmspace.h>

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn Max7219 Pin 1
pin 11 is connected to the CLK Max7219 Pin12
pin 10 is connected to LOAD Max7219 Pin 13
We have four MAX72XX.
*/
int Pin11 = 11;
int Pin12 = 12;
int Pin13 = 13;
int Number_of_Max = 4;

LedControl lc=LedControl(Pin11,Pin13,Pin12,Number_of_Max);

// Data of the sprite
const uint8_t sprite_xy[][8] PROGMEM = {
{145,40,68,146,73,34,20,137},
};

uint8_t screen_mem[8];

void setup() {
/*The MAX72XX is in power-saving mode on startup, we have to do a wakeup call /
lc.shutdown(0,false);
lc.shutdown(1,false);
lc.shutdown(2,false);
lc.shutdown(3,false);
/
Set the brightness to a medium values /
lc.setIntensity(0,15);
lc.setIntensity(1,15);
lc.setIntensity(2,15);
lc.setIntensity(3,15);
/
and clear the display */
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
}

// Copy sprite data to memory
void copy_to_buffer(const prog_uint8_t sprite[8]) {
memcpy_P(screen_mem, sprite, 8);
}

// Switch the LED (Rows) on
void writeSpriteOnMatrix() {
int i;
for (i=0; i<8; i++) {
lc.setRow(0,i,screen_mem*);*

  • }*
  • delay(1000);*
  • lc.clearDisplay(0);*
    }
    // Draw the sprite
    void Draw_Matrix() {
  • copy_to_buffer(sprite_xy[0]);*
  • writeSpriteOnMatrix();*
    }
    // Now moving the sprite across matrix 1...2...3...4
    void MoveSpriteRightOnMatrix() {
  • int k;*
  • int l;*
    for (l = 0; l< 32; l++) { // 4 x 8 = 32 Rows to move
  • if (l < 8); {*
  • for (k=0; k<8; k++) {*
  • lc.setRow(0,k+l,screen_mem[k]); // 1.Max7219*
  • }*
  • if ((l >= 8) && (l< 16)); {*
  • for (k=0; k<8; k++) {*
  • lc.setRow(1,k+l-8,screen_mem[k]); // 2. Max7219*
  • }*
  • if ((l >= 16) && (l< 24)); {*
  • for (k=0; k<8; k++) {*
  • lc.setRow(2,k+l-16,screen_mem[k]); // 3. Max7219*
  • }*
  • if (l >= 24); {*
  • for (k=0; k<8; k++) {*
  • lc.setRow(3,k+l-24,screen_mem[k]); // 4. Max7219*
  • }*
  • delay(50);*
  • lc.clearDisplay(0);*
  • lc.clearDisplay(1);*
  • lc.clearDisplay(2);*
  • lc.clearDisplay(3);*
  • }*
  • } *
  • }*
  • }*
    }
    }
    void loop() {
    // First Draw the sprite onto the 1. matrix
  • Draw_Matrix();*
    // Then move the sprite to the right
  • MoveSpriteRightOnMatrix();*
    }
    - - - - - - - - - -
    Maybe the code is not optimized but it works and hopefully will help to understand things.
    Actually I try to find out how to move the Characters from the 5x7-Font across multiple Max7219.
    Have fun. Any replies are welcome.
    Kind regards.
    Rainer_S
    matrix_8x8.bmp (96.1 KB)

Thank you, Rainer_S!

For 5x7 check http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267707310

Need help too. I used the code posted but it seems that there is a sort of bug... when I tried it, the display is shifted one column to the left (so it overflows to the first column on after 8 shifts - 1 full scroll)... please tell me where I should make the correction on the code... I am a newbie on using arduino... just 1 week old..