Categories

Arduino MAX7219 7 segment display module example

The MAX7219  is a compact, serial input/output common-cathode display drivers that interface microprocessors (µPs) to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers, and an 8×8 static RAM that stores each digit. Only one external resistor is required to set the segment current for all LEDs.

In this example we will use one of the MAX7219 modules with 7 segment displays that can be bought cheaply

These typically look like this

max7219-seven-segment-display

Connection

Vcc is connected to the VCC pin
Gnd is connected to the Gnd pin
pin 12 is connected to the DIN pin
pin 11 is connected to the CLK pin
pin 10 is connected to the CS pin

Code

This requires the LedControl library to be installed – https://github.com/wayoda/LedControl

#include "LedControl.h"
 
LedControl lc=LedControl(12,11,10,1);
// pin 12 is connected to the DIN pin
// pin 11 is connected to the CLK pin
// pin 10 is connected to the CS pin
// 1 as we are only using 1 MAX7219
 
void setup()
{
  // the zero refers to the 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
}
 
void loop()
{
  //numbers 7 to 0
  for (int a=0; a<8; a++)
  {
    lc.setDigit(0,a,a,false);
    delay(100);
  }
  delay(1000);
  //display number 8 on all segments
  for (int a=0; a<8; a++)
  {
    lc.setDigit(0,a,8,false);
    delay(100);
  }
  delay(1000);
  //
  for (int a=8; a>=0; a--)
  {
    lc.setDigit(0,a,a,false);
    delay(100);
  }
}

 

Links
8 digit 7 segment digit LED display can cascade finished product MAX7219 module

Share

Random flashing MAX7219 example

Another MAX7219 example using random numbers to randomly light an LED in the matrix, you may want to increase the delay

Download and install the LedControl Arduino library as it is essential for using the MAX7219.

Code

#include “LedControl.h” //  need the library
LedControl lc=LedControl(12,11,10,1); //

// pin 12 is connected to the MAX7219 pin 1 labelled DIN
// pin 11 is connected to the CLK pin 13 labelled CLK
// pin 10 is connected to LOAD pin 12 labelled as CS
// 1 as we only have 1 MAX 7219 atatched
long randNumberX;
long randNumberY;

void setup()
{
// the zero refers to the MAX7219 number
lc.shutdown(0,false);// turn off power saving
lc.setIntensity(0,4);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
Serial.begin(9600);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
randomSeed(analogRead(0));
}

void loop()
{
randNumberX = random(0,8);
randNumberY = random(0,8);
lc.setLed(0,randNumberX,randNumberY,true); // turns on LED at col, row
delay(20);
lc.setLed(0,randNumberX,randNumberY,false); // turns on LED at col, row
delay(20);

}

Links

MAX7219 on Amazon UK

Max7219 on Amazon

Share

MAX7219 example

The first thing you will need is to download and install the LedControl Arduino library as it is essential for using the MAX7219.

 

Code

#include “LedControl.h” //  need the library
LedControl lc=LedControl(12,11,10,1); //

// pin 12 is connected to the MAX7219 pin 1 labelled DIN
// pin 11 is connected to the CLK pin 13 labelled CLK
// pin 10 is connected to LOAD pin 12 labelled as CS
// 1 as we only have 1 MAX 7219 atatched

void setup()
{
// the zero refers to the MAX7219 number
lc.shutdown(0,false);// turn off power saving
lc.setIntensity(0,4);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
}

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);
}
}
}

 

Links

MAX7219 on Amazon UK

Max7219 on Amazon

Share

8×8 LED matrix example

This example switches on all the LEDs on a 8×8 LED matrix, the matrix is controlled by a MAX7219

LED matrix

LED matrix

You will need the Led Control library

#include “LedControl.h”

/*
Max7219_pinCLK = 10;
Max7219_pinCS = 9;
Max7219_pinDIN = 8;
*/
LedControl lc=LedControl(8,10,9,1);

unsigned char i;
unsigned char j;
unsigned long delaytime=100;

void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
}

void single() {
for(int row=0;row<8;row++)
{
for(int col=0;col<8;col++)
{
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
for(int i=0;i<col;i++)
{
lc.setLed(0,row,col,false);
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
}
}
}
}

void loop()
{
single();
lc.clearDisplay(0);
}

Share