MAX7219
#include <LedControl.h>
Sooner or later Arduino enthusiasts and beginners alike will come across the
MAX7219 IC. And for good reason, it’s a simple and somewhat inexpensive method
of controlling 64 LEDs in either matrix or numeric display form. Furthermore
they can be chained together to control two or more units for even more LEDs.
Overall – they’re a lot of fun and can also be quite useful, so let’s get started.
Here’s an example of a MAX7219 and another IC which is a functional equivalent,
the AS1107 from Austria Microsystems. You might not see the AS1107 around much,
but it can be cheaper – so don’t be afraid to use that instead:
At first glance you may think that it takes a lot of real estate, but it saves
some as well. As mentioned earlier, the MAX7219 can completely control 64
individual LEDs – including maintaining equal brightness, and allowing you to
adjust the brightness of the LEDs either with hardware or software ( or both ).
It can refresh the LEDs at around 800 Hz, so no more flickering, uneven LED
displays.
You can even switch the display off for power saving mode, and still send it
data while it is off. And another good thing – when powered up, it keeps the
LEDs off, so no wacky displays for the first seconds of operation. For more
technical information, here is the data sheet: MAX7219.pdf. Now to put it to
work for us – we’ll demonstrate using one or more 8 x 8 LED matrix displays, as
well as 8 digits of 7-segment LED numbers.
Before continuing, download and install the LedControl Arduino library as it is
essential for using the MAX7219.
Controlling LED matrix displays with the MAX7219
First of all, let’s examine the hardware side of things. Here is the pinout
diagram for the MAX7219:
The MAX7219 drives eight LEDs at a time, and by rapidly switching banks of
eight your eyes don’t see the changes. Wiring up a matrix is very simple – if
you have a common matrix with the following schematic:
MAX7219 LED driver IC from PMD Way
connect the MAX7219 pins labelled DP, A~F to the row pins respectively, and the
MAX7219 pins labelled DIG0~7 to the column pins respectively. A total example
circuit with the above matrix is as follows:
MAX7219 LED driver IC from PMD Way
The circuit is quite straight forward, except we have a resistor between 5V and
MAX7219 pin 18. The MAX7219 is a constant-current LED driver, and the value of
the resistor is used to set the current flow to the LEDs. Have a look at table
eleven on page eleven of the data sheet:
MAX7219 LED driver IC from PMD Way
You’ll need to know the voltage and forward current for your LED matrix or
numeric display, then match the value on the table. E.g. if you have a 2V 20 mA
LED, your resistor value will be 28kΩ ( the values are in kΩ ). Finally, the
MAX7219 serial in, load and clock pins will go to Arduino digital pins which
are specified in the sketch. We’ll get to that in the moment, but before that
let’s return to the matrix modules.
In the last few months there has been a proliferation of inexpensive kits that
contain a MAX7219 or equivalent, and an LED matrix. These are great for
experimenting with and can save you a lot of work – some examples of which are
shown below:
MAX7219 LED driver IC from PMD Way
Now for the sketch. You need the following two lines at the beginning of the
sketch:
/*F********************************************************************
*
**********************************************************************/
#include "LedControl.h"
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
LedControl lc =LedControl( 12,11,10,1 );
The first pulls in the library, and the second line sets up an instance to
control. The four parameters are as follows:
the digital pin connected to pin 1 of the MAX7219 ( “data in” )
the digital pin connected to pin 13 of the MAX7219 ( “CLK or clock” )
the digital pin connected to pin 12 of the MAX7219 ( “LOAD” )
The number of MAX7219s connected.
If you have more than one MAX7219, connect the DOUT ( “data out” ) pin of the
first MAX7219 to pin 1 of the second, and so on. However the CLK and LOAD pins
are all connected in parallel and then back to the Arduino.
Next, two more vital functions that you’d normally put in void setup( ):
lc.shutdown( 0,false );
lc.setIntensity( 0,8 );
The first line above turns the LEDs connected to the MAX7219 on. If you set TRUE
, you can send data to the MAX7219 but the LEDs will stay off. The second line
adjusts the brightness of the LEDs in sixteen stages. For both of those
functions ( and all others from the LedControl ) the first parameter is the number
of the MAX7219 connected. If you have one, the parameter is zero… for two
MAX7219s, it’s 1 and so on.
Finally, to turn an individual LED in the matrix on or off, use:
lc.setLed( 0,col,row,true );
which turns on an LED positioned at col, row connected to MAX7219 #1. Change
TRUE to FALSE to turn it off. These functions are demonstrated in the following
sketch:
/*F********************************************************************
*
**********************************************************************/
#include "LedControl.h" // NEED LIBRARY
//************************* DEFINES ************************************
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
LedControl lc =LedControl( 12, 11, 10, 1 ); //
/*F********************************************************************
*
**********************************************************************/
void
setup( )
{
// ZERO REFERS TO MAX7219 NUMBER, IT IS ZERO FOR 1 CHIP
lc.shutdown( 0, false ); // TURN OFF POWER SAVING, ENABLES DISPLAY
lc.setIntensity( 0, 8 ); // SETS BRIGHTNESS ( 0~15 POSSIBLE VALUES)
lc.clearDisplay( 0 ); // CLEAR SCREEN
}
/*F********************************************************************
*
**********************************************************************/
void
loop( )
{
for( int row =0; row < 8; row++ )
{
for( int col =0; col < 8; col++ )
{
lc.setLed( 0,col , row, true ); // TURNS ON LED AT COL, ROW
delay( 25 );
}
}
for( int row =0; row < 8; row++ )
{
for( int col =0; col < 8; col++ )
{
lc.setLed( 0, col, row, false ); // TURNS OFF LED AT COL, ROW
delay( 25 );
}
}
}
And a quick video of the results:
How about controlling two MAX7219s? Or more? The hardware modifications are easy
– connect the serial data out pin from your first MAX7219 to the data in pin on
the second ( and so on ), and the LOAD and CLOCK pins from the first MAX7219
connect to the second ( and so on ). You will of course still need the 5V, GND,
resistor, capacitors etc. for the second and subsequent MAX7219.
You will also need to make a few changes in your sketch. The first is to tell it
how many MAX7219s you’re using in the following line:
LedControl lc =LedControl( 12, 11, 10, X );
by replacing X with the quantity. Then whenever you’re using a MAX7219 function
, replace the ( previously used ) zero with the number of the MAX7219 you wish
to address. They are numbered from zero upwards, with the MAX7219 directly
connected to the Arduino as unit zero, then one etc. To demonstrate this, we
replicate the previous example but with two MAX7219s:
/*H********************************************************************
*
**********************************************************************/
#include "LedControl.h" // NEED THE LIBRARY
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
LedControl lc =LedControl( 12, 11, 10, 2 ); //
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
/*F********************************************************************
*
**********************************************************************/
void
setup( )
{
lc.shutdown( 0, false ); // TURN OFF POWER SAVING, ENABLES DISPLAY
lc.setIntensity( 0, 8 ); // SETS BRIGHTNESS ( 0~15 POSSIBLE VALUES )
lc.clearDisplay( 0 ); // CLEAR SCREEN
lc.shutdown( 1, false ); // TURN OFF POWER SAVING, ENABLES DISPLAY
lc.setIntensity( 1, 8 ); // SETS BRIGHTNESS ( 0~15 POSSIBLE VALUES )
lc.clearDisplay( 1 ); // CLEAR SCREEN
}
/*F********************************************************************
*
**********************************************************************/
void
loop( )
{
for( int row =0; row < 8; row++ )
{
for( int col =0; col < 8; col++ )
{
lc.setLed( 0, col, row, true ); // TURNS ON LED AT COL, ROW
lc.setLed( 1, col, row, false ); // TURNS ON LED AT COL, ROW
delay( 25 );
}
}
for( int row =0; row < 8; row++ )
{
for( int col =0; col < 8; col++ )
{
lc.setLed( 0, col, row, false ); // TURNS OFF LED AT COL, ROW
lc.setLed( 1, col, row, true ); // TURNS ON LED AT COL, ROW
delay( 25 );
}
}
}
And again, a quick demonstration:
Another fun use of the MAX7219 and LED matrices is to display scrolling text.
For the case of simplicity we’ll use the LedControl library and the two LED
matrix modules from the previous examples.
First our example sketch – it is quite long however most of this is due to
defining the characters for each letter of the alphabet and so on. We’ll explain
it at the other end!
// based on an orginal sketch by Arduino forum member "danigom"
// http://forum.arduino.cc/index.php?action=profile;u=188950
/*H********************************************************************
*
**********************************************************************/
#include <avr/pgmspace.h>
#include <LedControl.h>
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
const int numDevices = 2; // number of MAX7219s used
const long scrollDelay = 75; // adjust scrolling speed
unsigned long bufferLong [14] = {0};
LedControl lc =LedControl( 12, 11, 10, numDevices );
prog_uchar scrollText[] PROGMEM ={
" THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG 1234567890 the quick brown"
" fox jumped over the lazy dog "};
/*F********************************************************************
*
**********************************************************************/
void
setup( )
{
for( int x=0; x < numDevices; x++ )
{
lc.shutdown( x, false );// MAX72XX IS IN POWER-SAVING MODE ON STARTUP
lc.setIntensity( x, 8 ); // SET BRIGHTNESS TO DEFAULT VALUE
lc.clearDisplay( x ); // AND CLEAR DISPLAY
}
}
/*F********************************************************************
*
**********************************************************************/
void
loop( )
{
scrollMessage( scrollText );
scrollFont( );
}
/*D********************************************************************
*
**********************************************************************/
byte Font5x7[] =
{ // FONT MATRIX (ARRANGED AS 7X FONT DATA + 1X KERNING DATA)
// Space (Char 0x20)
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,
6,
//!
B10000000, B10000000, B10000000, B10000000, B00000000, B00000000, B10000000,
2,
//"
B10100000, B10100000, B10100000, B00000000, B00000000, B00000000, B00000000,
4,
//#
B01010000, B01010000, B11111000, B01010000, B11111000, B01010000, B01010000,
6,
//$
B00100000, B01111000, B10100000, B01110000, B00101000, B11110000, B00100000,
6,
//%
B11000000, B11001000, B00010000, B00100000, B01000000, B10011000, B00011000,
6,
//&
B01100000, B10010000, B10100000, B01000000, B10101000, B10010000, B01101000,
6,
//'
B11000000, B01000000, B10000000, B00000000, B00000000, B00000000, B00000000,
3,
//(
B00100000, B01000000, B10000000, B10000000, B10000000, B01000000, B00100000,
4,
// )
B10000000, B01000000, B00100000, B00100000, B00100000, B01000000, B10000000,
4,
//*
B00000000, B00100000, B10101000, B01110000, B10101000, B00100000, B00000000,
6,
//+
B00000000, B00100000, B00100000, B11111000, B00100000, B00100000, B00000000,
6,
//,
B00000000, B00000000, B00000000, B00000000, B11000000, B01000000, B10000000,
3,
//-
B00000000, B00000000, B11111000, B00000000, B00000000, B00000000, B00000000,
6,
//.
B00000000, B00000000, B00000000, B00000000, B00000000, B11000000, B11000000,
3,
///
B00000000, B00001000, B00010000, B00100000, B01000000, B10000000, B00000000,
6,
//0
B01110000, B10001000, B10011000, B10101000, B11001000, B10001000, B01110000,
6,
//1
B01000000, B11000000, B01000000, B01000000, B01000000, B01000000, B11100000,
4,
//2
B01110000, B10001000, B00001000, B00010000, B00100000, B01000000, B11111000,
6,
//3
B11111000, B00010000, B00100000, B00010000, B00001000, B10001000, B01110000,
6,
//4
B00010000, B00110000, B01010000, B10010000, B11111000, B00010000, B00010000,
6,
//5
B11111000, B10000000, B11110000, B00001000, B00001000, B10001000, B01110000,
6,
//6
B00110000, B01000000, B10000000, B11110000, B10001000, B10001000, B01110000,
6,
//7
B11111000, B10001000, B00001000, B00010000, B00100000, B00100000, B00100000,
6,
//8
B01110000, B10001000, B10001000, B01110000, B10001000, B10001000, B01110000,
6,
//9
B01110000, B10001000, B10001000, B01111000, B00001000, B00010000, B01100000,
6,
//:
B00000000, B11000000, B11000000, B00000000, B11000000, B11000000, B00000000,
3,
//;
B00000000, B11000000, B11000000, B00000000, B11000000, B01000000, B10000000,
3,
//<
B00010000, B00100000, B01000000, B10000000, B01000000, B00100000, B00010000,
5,
//=
B00000000, B00000000, B11111000, B00000000, B11111000, B00000000, B00000000,
6,
//>
B10000000, B01000000, B00100000, B00010000, B00100000, B01000000, B10000000,
5,
//?
B01110000, B10001000, B00001000, B00010000, B00100000, B00000000, B00100000,
6,
//@
B01110000, B10001000, B00001000, B01101000, B10101000, B10101000, B01110000,
6,
//A
B01110000, B10001000, B10001000, B10001000, B11111000, B10001000, B10001000,
6,
//B
B11110000, B10001000, B10001000, B11110000, B10001000, B10001000, B11110000,
6,
//C
B01110000, B10001000, B10000000, B10000000, B10000000, B10001000, B01110000,
6,
//D
B11100000, B10010000, B10001000, B10001000, B10001000, B10010000, B11100000,
6,
//E
B11111000, B10000000, B10000000, B11110000, B10000000, B10000000, B11111000,
6,
//F
B11111000, B10000000, B10000000, B11110000, B10000000, B10000000, B10000000,
6,
//G
B01110000, B10001000, B10000000, B10111000, B10001000, B10001000, B01111000,
6,
//H
B10001000, B10001000, B10001000, B11111000, B10001000, B10001000, B10001000,
6,
//I
B11100000, B01000000, B01000000, B01000000, B01000000, B01000000, B11100000,
4,
//J
B00111000, B00010000, B00010000, B00010000, B00010000, B10010000, B01100000,
6,
//K
B10001000, B10010000, B10100000, B11000000, B10100000, B10010000, B10001000,
6,
//L
B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B11111000,
6,
//M
B10001000, B11011000, B10101000, B10101000, B10001000, B10001000, B10001000,
6,
//N
B10001000, B10001000, B11001000, B10101000, B10011000, B10001000, B10001000,
6,
//O
B01110000, B10001000, B10001000, B10001000, B10001000, B10001000, B01110000,
6,
//P
B11110000, B10001000, B10001000, B11110000, B10000000, B10000000, B10000000,
6,
//Q
B01110000, B10001000, B10001000, B10001000, B10101000, B10010000, B01101000,
6,
//R
B11110000, B10001000, B10001000, B11110000, B10100000, B10010000, B10001000,
6,
//S
B01111000, B10000000, B10000000, B01110000, B00001000, B00001000, B11110000,
6,
//T
B11111000, B00100000, B00100000, B00100000, B00100000, B00100000, B00100000,
6,
//U
B10001000, B10001000, B10001000, B10001000, B10001000, B10001000, B01110000,
6,
//V
B10001000, B10001000, B10001000, B10001000, B10001000, B01010000, B00100000,
6,
//W
B10001000, B10001000, B10001000, B10101000, B10101000, B10101000, B01010000,
6,
//X
B10001000, B10001000, B01010000, B00100000, B01010000, B10001000, B10001000,
6,
//Y
B10001000, B10001000, B10001000, B01010000, B00100000, B00100000, B00100000,
6,
//Z
B11111000, B00001000, B00010000, B00100000, B01000000, B10000000, B11111000,
6,
//[
B11100000, B10000000, B10000000, B10000000, B10000000, B10000000, B11100000,
4,
//( Backward Slash )
B00000000, B10000000, B01000000, B00100000, B00010000, B00001000, B00000000,
6,
//]
B11100000, B00100000, B00100000, B00100000, B00100000, B00100000, B11100000,
4,
//^
B00100000, B01010000, B10001000, B00000000, B00000000, B00000000, B00000000,
6,
//_
B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11111000,
6,
//`
B10000000, B01000000, B00100000, B00000000, B00000000, B00000000, B00000000,
4,
//a
B00000000, B00000000, B01110000, B00001000, B01111000, B10001000, B01111000,
6,
//b
B10000000, B10000000, B10110000, B11001000, B10001000, B10001000, B11110000,
6,
//c
B00000000, B00000000, B01110000, B10001000, B10000000, B10001000, B01110000,
6,
//d
B00001000, B00001000, B01101000, B10011000, B10001000, B10001000, B01111000,
6,
//e
B00000000, B00000000, B01110000, B10001000, B11111000, B10000000, B01110000,
6,
//f
B00110000, B01001000, B01000000, B11100000, B01000000, B01000000, B01000000,
6,
//g
B00000000, B01111000, B10001000, B10001000, B01111000, B00001000, B01110000,
6,
//h
B10000000, B10000000, B10110000, B11001000, B10001000, B10001000, B10001000,
6,
//i
B01000000, B00000000, B11000000, B01000000, B01000000, B01000000, B11100000,
4,
//j
B00010000, B00000000, B00110000, B00010000, B00010000, B10010000, B01100000,
5,
//k
B10000000, B10000000, B10010000, B10100000, B11000000, B10100000, B10010000,
5,
//l
B11000000, B01000000, B01000000, B01000000, B01000000, B01000000, B11100000,
4,
//m
B00000000, B00000000, B11010000, B10101000, B10101000, B10001000, B10001000,
6,
//n
B00000000, B00000000, B10110000, B11001000, B10001000, B10001000, B10001000,
6,
//o
B00000000, B00000000, B01110000, B10001000, B10001000, B10001000, B01110000,
6,
//p
B00000000, B00000000, B11110000, B10001000, B11110000, B10000000, B10000000,
6,
//q
B00000000, B00000000, B01101000, B10011000, B01111000, B00001000, B00001000,
6,
//r
B00000000, B00000000, B10110000, B11001000, B10000000, B10000000, B10000000,
6,
//s
B00000000, B00000000, B01110000, B10000000, B01110000, B00001000, B11110000,
6,
//t
B01000000, B01000000, B11100000, B01000000, B01000000, B01001000, B00110000,
6,
//u
B00000000, B00000000, B10001000, B10001000, B10001000, B10011000, B01101000,
6,
//v
B00000000, B00000000, B10001000, B10001000, B10001000, B01010000, B00100000,
6,
//w
B00000000, B00000000, B10001000, B10101000, B10101000, B10101000, B01010000,
6,
//x
B00000000, B00000000, B10001000, B01010000, B00100000, B01010000, B10001000,
6,
//y
B00000000, B00000000, B10001000, B10001000, B01111000, B00001000, B01110000,
6,
//z
B00000000, B00000000, B11111000, B00010000, B00100000, B01000000, B11111000,
6,
//{
B00100000, B01000000, B01000000, B10000000, B01000000, B01000000, B00100000,
4,
//|
B10000000, B10000000, B10000000, B10000000, B10000000, B10000000, B10000000,
2,
//}
B10000000, B01000000, B01000000, B00100000, B01000000, B01000000, B10000000,
4,
//~
B00000000, B00000000, B00000000, B01101000, B10010000, B00000000, B00000000,
6,
// ( Char 0x7F )
B01100000, B10010000, B10010000, B01100000, B00000000, B00000000, B00000000,
5
};
/*F********************************************************************
*
**********************************************************************/
void
scrollFont( )
{
for( int counter = 0x20; counter < 0x80; counter++ )
{
loadBufferLong( counter );
delay( 500 );
}
}
/*F********************************************************************
* Scroll Message
**********************************************************************/
void
scrollMessage( prog_uchar * messageString )
{
int counter = 0;
int myChar=0;
do{
// READ BACK A CHAR
myChar = pgm_read_byte_near( messageString + counter);
if( myChar != 0 )
loadBufferLong( myChar );
counter++;
}
while( myChar != 0 );
}
/*F********************************************************************
* Load character into scroll buffer
**********************************************************************/
void
loadBufferLong( int ascii )
{
if( ascii >= 0x20 && ascii <= 0x7f )
{
for( int a =0; a < 7; a++ )
{ // LOOP 7 TIMES FOR A 5X7 FONt
unsigned long c = pgm_read_byte_near( font5x7 + ((ascii - 0x20)
* 8 ) + a );// NDX INTO CHAR TBL GET ROW DAT
unsigned long x = bufferLong [a*2]; // LOAD CURR SCROLL BUFFER
x = x | c; // OR NEW CHARACTER ONTO END OF CURRENT
bufferLong [a*2] = x; // STORE IN BUFFER
}
byte count = pgm_read_byte_near( font5x7 + (( ascii - 0x20 ) * 8 ) + 7);
// NDX INTO CHAR TBL FOR KERNING DATA
for( byte x =0; x < count; x++ )
{
rotateBufferLong( );
printBufferLong( );
delay( scrollDelay );
}
}
}
/*F********************************************************************
* Rotate buffer
**********************************************************************/
void
rotateBufferLong( )
{
for( int a =0; a < 7; a++ )
{ // LOOP 7 TIMES FOR A 5X7 FONT
unsigned long x = bufferLong [a*2]; // GET LOW BUFFER ENTRY
byte b = bitRead( x, 31 ); // CPY HI BIT GETS LOST IN ROTATION
x = x<<1; // ROTATE LEFT ONE BIT
bufferLong [a*2] = x; // STORE NEW LOW BUFFER
x = bufferLong [a*2+1]; // GET HIGH BUFFER ENTRY
x = x<<1; // ROTATE LEFT ONE BIT
bitWrite( x,0,b ); // STORE SAVED BIT
bufferLong [a*2+1] = x; // STORE NEW HIGH BUFFER
}
}
/*F********************************************************************
* DISPLAY BUFFER ON LED MATRIX
**********************************************************************/
void
printBufferLong( )
{
for( int a =0; a < 7; a++ )
{ // LOOP 7 TIMES FOR A 5X7 FONT
unsigned long x = bufferLong[a *2 +1]; // GET HIGH BUFFER ENTRY
byte y = x; // MASK OFF FIRST CHARACTER
lc.setRow( 3, a, y ); // SEND ROW TO RELEVENT MAX7219 CHIP
x = bufferLong [a*2]; // GET LOW BUFFER ENTRY
y = ( x >> 24 ); // MASK OFF SECOND CHARACTER
lc.setRow( 2,a,y ); // SEND ROW TO RELEVENT MAX7219 CHIP
y = ( x >> 16 ); // MASK OFF THIRD CHARACTER
lc.setRow( 1,a,y ); // SEND ROW TO RELEVENT MAX7219 CHIP
y = ( x >> 8 ); // MASK OFF FORTH CHARACTER
lc.setRow( 0,a,y ); // SEND ROW TO RELEVENT MAX7219 CHIP
}
}
The pertinent parts are at the top of the sketch – the following line sets the
number of MAX7219s in the hardware:
const int numDevices = 2;
The following can be adjusted to change the speed of text scrolling:
const long scrollDelay = 75;
… then place the text to scroll in the following ( for example ):
prog_uchar scrollText[] PROGMEM ={
" THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG 1234567890 the quick "
"brown fox jumped over the lazy dog "};
Finally – to scroll the text on demand, use the following:
scrollMessage( scrollText );
You can then incorporate the code into your own sketches. And a video of the
example sketch in action:
Although we used the LedControl library, there are many others out there for
scrolling text. One interesting example is Parola – which is incredibly
customisable.
Controlling LED numeric displays with the MAX7219
Using the MAX7219 and the LedControl library you can also drive numeric LED
displays – up to eight digits from the one MAX7219. This gives you the ability
to make various numeric displays that are clear to read and easy to control.
When shopping around for numeric LED displays, make sure you have the
common-cathode type.
Connecting numeric displays is quite simple, consider the following schematic
which should appear familiar by now:
MAX7219 LED driver IC from PMD Way
The schematic shows the connections for modules or groups of up to eight digits.
Each digit’s A~F and dp ( decimal point ) anodes connect together to the MAX7219,
and each digit’s cathode connects in order as well. The MAX7219 will display
each digit in turn by using one cathode at a time. Of course if you want more
than eight digits, connect another MAX7219 just as we did with the LED matrices
previously.
The required code in the sketch is identical to the LED matrix code, however to
display individual digits we use:
lc.setDigit( A, B, C, D );
where A is the MAX7219 we’re using, B is the digit to use ( from a possible 0 to
7 ), C is the digit to display ( 0~9… if you use 10~15 it will display A~F
respectively ) and D is false/true ( digit on or off ). You can also send basic
characters such as a dash “-” with the following:
lc.setChar( A, B, '-', false );
Now let’s put together an example of eight digits:
/*F********************************************************************
*
**********************************************************************/
#include "LedControl.h" // need the library
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
LedControl lc = LedControl( 12, 11, 10, 1 ); // LC IS OUR OBJECT
// pin 12 is connected to the MAX7219 PIN 1
// pin 11 is connected to the CLK PIN 13
// pin 10 is connected to LOAD PIN 12
// 1 as we are only using 1 MAX7219
/*F********************************************************************
*
**********************************************************************/
void
setup( )
{ // ZERO REFERS TO MAX7219 NUMBER, IT IS ZERO FOR 1 CHIP
lc.shutdown( 0, false ); // TURN OFF POWER SAVING, ENABLES DISPLAY
lc.setIntensity( 0, 8 ); // SETS BRIGHTNESS ( 0~15 POSSIBLE VALUES)
lc.clearDisplay( 0 ); // CLEAR SCREEN
}
/*F********************************************************************
*
**********************************************************************/
void
loop( )
{
for( int a =0; a < 8; a++ )
{
lc.setDigit( 0, a, a, true );
delay( 100 );
}
for( int a =0; a < 8; a++ )
{
lc.setDigit( 0, a, 8, 1 );
delay( 100 );
}
for( int a =0; a < 8; a++ )
{
lc.setDigit( 0, a, 0, false );
delay( 100 );
}
for( int a =0; a < 8; a++ )
{
lc.setChar( 0, a, ' ', false );
delay( 100 );
}
for( int a =0; a < 8; a++ )
{
lc.setChar( 0, a, '-', false );
delay( 100 );
}
for( int a =0; a < 8; a++ )
{
lc.setChar( 0, a, ' ', false );
delay( 100 );
}
}
and sketch in action:
Conclusion
We have only scratched the surface of what is possible with the MAX7219 and
compatible parts. They’re loads of fun and quite useful as well.
This post brought to you by pmdway.com – everything for makers and electronics
enthusiasts, with free delivery worldwide.
To keep up to date with new posts at tronixstuff.com, please subscribe to the
mailing list in the box on the right, or follow us on twitter @tronixstuff.
Please share with others:
TwitterFacebookLinkedInPinterest3EmailRedditTumblrPrint
Loading...
This entry was posted in arduino, as1107, COM-09622, LED matrix, lesson,
max7219, part review, tronixstuff, tutorial and tagged arduino, AS1107, austria,
circuit, COM-09622, compatible, display, equivalent, example, guide, guides,
LED, LED matrix, lesson, lessons, MAX7219, Maxim 7219, micro, microsystems,
part review, PMDway, review, tronixstuff, tutorial on October 11, 2013 by John
Boxall.
About John Boxall
https://johnboxall.com
View all posts by John Boxall →
Post navigation
← Kit Review – Sinclair Cambridge Calculator Tutorial – Arduino and the TLC5940 PWM LED Driver IC →
A Hands-On Introduction with 60 Projects
This friendly project-based book will turn Arduino beginners into advanced
Arduinians with the skills and inspiration needed to construct their own
professional or hobbyist devices!
A Hands-On Introduction with 65 Projects!
Search
Search for: