This Arduino library is written to work with the MAX7219 LED driver IC. The library will allow you to control one or more of these IC's that have been serially connected together.
The library also currently supports the 8 digit 7 segment display module (HCMODU0082) and provides compatible commands and an alphanumeric character set. Future updates are planned to include other MAX7219 based products.
You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
or similarly for Linux.
To use the library just include the HCMAX7219.h header file and create an instance of the library. E.g:
Code: Select all
#include <HCMAX7219.h>
HCMAX7219 HCMAX7219(LOAD);
LOAD is the number for the digital pin connected to the first MAX7219 's LOAD (CS) pin.
The following functions are available with this library:
Code: Select all
HCMAX7219.Init();
Code: Select all
HCMAX7219.Write(Address, Data, Driver)
Address is the address of the register to write to and can be one of the following pre-defined values:
MAX7219NOOP
MAX7219DIGIT1
MAX7219DIGIT2
MAX7219DIGIT3
MAX7219DIGIT4
MAX7219DIGIT5
MAX7219DIGIT6
MAX7219DIGIT7
MAX7219DIGIT8
MAX7219DECODE
MAX7219INTESITY
MAX7219SCANLIMIT
MAX7219SHUTDOWN
MAX7219TEST
Data is a value of type Byte to write to the register.
Driver is a value of type Byte which driver in the chain to access. 0 being the first.
Code: Select all
HCMAX7219.Shutdown(Mode, Driver)
Mode is of type boolean and can be one of the following pre-defined values:
MAX7219OFF
MAX7219ON
Driver is a value of type Byte which driver in the chain to access. 0 being the first.
Code: Select all
HCMAX7219.TestMode(Mode, Driver)
Mode is of type boolean and can be one of the following pre-defined values:
TESTMODEOFF
TESTMODEON
Driver is a value of type Byte which driver in the chain to access. 0 being the first.
Code: Select all
HCMAX7219.SevenSegDigits(Digits, Driver)
0 (Digit 0)
1 (Digit 0 & 1)
2 (Digit 0, 1 & 2)
3 (Digit 0, 1, 2, & 3)
4 (Digit 0, 1, 2, 3 & 4)
5 (Digit 0, 1, 2, 3, 4 & 5)
6 (Digit 0, 1, 2, 3, 4, 5, & 6)
7 (Digit 0, 1, 2, 3, 4, 5,, 6 & 7)
Driver is a value of type Byte which driver in the chain to access. 0 being the first.
Code: Select all
HCMAX7219.Intensity(Level, Driver)
Driver is a value of type Byte which driver in the chain to access. 0 being the first.
Code: Select all
HCMAX7219.Clear()
Code: Select all
HCMAX7219.Refresh()
Code: Select all
HCMAX7219.DisplayBuffer[]
Setting the number off drivers:
By default the library assumes that you only have one driver connected. If you are connecting multiple drivers together you can set the number of drivers you have by changing the following line in the HCMAX7219.h header file:
Code: Select all
#define NUMBEROFDRIVERS 1
8 digit 7 segment display module (HCMODU0082) specific commands:
Code: Select all
HCMAX7219.print7Seg("TEXT STRING", Offset)
Code: Select all
HCMAX7219.print7Seg(Value, DP, Digits, Offset)
Value is the number to print.
DP specifies the number of decimal places to display the floating point number to.
Digits is the total number of digits to display. If the number is smaller than the specified number of digits it will pad
the left side of the number with spaces.
Offset is the column position from where the value will start from. Valid values are from 0 to 65535 (Uno/Nano etc) where:
1 = right most column
8 = left most column
Values above 8 will start the text at a column beyond the left most column.
Code: Select all
HCMAX7219.print7Seg(Value, Offset)
Code: Select all
HCMAX7219.print7Seg(Value, Decimal_Position, Offset)
Decimal_Position allows the option to specify the position of a decimal point.
See above of description of Offset.
8x8 serial dot matrix module (HCOPTO0014) specific commands:
Code: Select all
HCMAX7219.printMatrix("TEXT STRING", Offset)
Code: Select all
HCMAX7219.printMatrix(Value, Offset)
Code: Select all
HCMAX7219.printMatrix(Value, Decimal_Position, Offset)
Decimal_Position allows the option to specify the position of a decimal point.
See above of description of Offset.
Code: Select all
HCMAX7219.Invert(Mode);
INVERTOFF
INVERTON
Code: Select all
/* FILE: HCMODU0082_Serial_7_Segment_Module_Example1
DATE: 19/03/15
VERSION: 0.2
REVISIONS:
12/03/15 Created version 0.1
19/03/15 Updated to work with V0.2 of the HCMAX7219 library
This is an example of how to use the Hobby Components serial 8 digit seven 7
segment display module (HCMODU0082). To use this example sketch you will
need to download and install the HCMAX7921 library available from the software
section of our support forum (forum.hobbycomponents.com) or on github:
(https://github.com/HobbyComponents)
The library assumes you are using one module. If you have more than one module
connected together then you will need to change the following line in the
libraries HCMAX7219.h header file to the number of drivers you have connected:
#define NUMBEROFDRIVERS 1 <- Change this number
PINOUT:
MODULE.....UNO/NANO.....MEGA
VCC........+5V..........+5V
GND........GND..........GND
DIN........11...........51
CS (LOAD)..10...........10
CLK........13...........52
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of promoting products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */
/* Include the HCMAX7219 and SPI library */
#include <HCMAX7219.h>
#include "SPI.h"
/* Set the LOAD (CS) digital pin number*/
#define LOAD 10
/* Create an instance of the library */
HCMAX7219 HCMAX7219(LOAD);
void setup()
{
HCMAX7219.Init();
}
/* Main program */
void loop()
{
/* Clear the output buffer */
HCMAX7219.Clear();
/* Write some text to the output buffer */
HCMAX7219.print7Seg("HELLO !!",8);
/* Send the output buffer to the display */
HCMAX7219.Refresh();
while(1);
}
Code: Select all
/* FILE: HCMODU0082_Serial_7_Segment_Module_Example2
DATE: 19/03/15
VERSION: 0.2
REVISIONS:
12/03/15 Created version 0.1
19/03/15 Updated to work with V0.2 of the HCMAX7219 library
This is an example of how to use the Hobby Components serial 8 digit seven 7
segment display module (HCMODU0082). To use this example sketch you will
need to download and install the HCMAX7921 library available from the software
section of our support forum (forum.hobbycomponents.com) or on github:
(https://github.com/HobbyComponents)
The library assumes you are using one module. If you have more than one module
connected together then you will need to change the following line in the
libraries HCMAX7219.h header file to the number of drivers you have connected:
#define NUMBEROFDRIVERS 1 <- Change this number
PINOUT:
MODULE.....UNO/NANO.....MEGA
VCC........+5V..........+5V
GND........GND..........GND
DIN........11...........51
CS (LOAD)..10...........10
CLK........13...........52
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of promoting products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */
/* Include the HCMAX7219 and SPI library */
#include <HCMAX7219.h>
#include "SPI.h"
/* Set the LOAD (CS) digital pin number*/
#define LOAD 10
/* Create an instance of the library */
HCMAX7219 HCMAX7219(LOAD);
void setup()
{
HCMAX7219.Init();
}
/* Main program */
void loop()
{
byte Loopcounter;
byte Position;
/* SCROLL SOME TEXT 5 TIMES BEFORE MOVING ON */
for (Loopcounter = 0; Loopcounter <= 5; Loopcounter++)
{
/* We are scrolling 30 characters of text across the entire display */
for (Position = 0; Position <= DISPLAYBUFFERSIZE + 30; Position++)
{
/* Write the test to the output buffer at the position we require */
HCMAX7219.print7Seg("HCMAX7219 SCROLLING TEXT DEMO ",Position);
/* Send the output buffer to the display */
HCMAX7219.Refresh();
delay(200);
}
}
/* WE CAN ALSO DISPLAY INTEGER NUMBERS */
/* Clear the output buffer */
HCMAX7219.Clear();
/* Write some text and output it*/
HCMAX7219.print7Seg("INT NUM.",8);
HCMAX7219.Refresh();
delay(2000);
/* display an example of a negative integer number */
HCMAX7219.Clear();
HCMAX7219.print7Seg(-1234567,8);
HCMAX7219.Refresh();
delay(2000);
/* Clear the output buffer */
HCMAX7219.Clear();
/* Write some text and output it*/
HCMAX7219.print7Seg("WITH DP.",8);
HCMAX7219.Refresh();
delay(2000);
/* Show the DP in different places. Notice when the DP is at the
beginning the number is padded with a zero */
HCMAX7219.Clear();
for (Position = 1; Position <= 7; Position++)
{
HCMAX7219.print7Seg(-1234567,Position,8);
HCMAX7219.Refresh();
delay(1000);
}
}
Code: Select all
/* FILE: HCMODU0082_Serial_Dot_Matrix_Example
DATE: 19/03/15
VERSION: 0.1
REVISIONS:
19/03/15 Created version 0.1
This is an example of how to use the Hobby Components 8x8 serial dot matrix
module (HCOPTO0014). To use this example sketch you will need to download
and install the HCMAX7921 library available from the software section of our
support forum (forum.hobbycomponents.com) or on github:
(https://github.com/HobbyComponents)
The library assumes you are using one module. If you have more than one module
connected together then you will need to change the following line in the
libraries HCMAX7219.h header file to the number of drivers you have connected:
#define NUMBEROFDRIVERS 1 <- Change this number
PINOUT:
MODULE.....UNO/NANO.....MEGA
VCC........+5V..........+5V
GND........GND..........GND
DIN........11...........51
CS (LOAD)..10...........10
CLK........13...........52
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of promoting products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */
/* Include the HCMAX7219 and SPI library */
#include <HCMAX7219.h>
#include "SPI.h"
/* Set the LOAD (CS) digital pin number*/
#define LOAD 10
/* Create an instance of the library */
HCMAX7219 HCMAX7219(LOAD);
void setup()
{
HCMAX7219.Init();
}
/* Main program */
void loop()
{
byte Loopcounter;
int Position;
/* Clear the output buffer */
HCMAX7219.Clear();
/* SCROLL SOME TEXT 2 TIMES BEFORE MOVING ON */
for (Loopcounter = 0; Loopcounter <= 2; Loopcounter++)
{
for(Position=0; Position <= 64; Position++)
{
HCMAX7219.printMatrix("HELLO!! ", Position);
HCMAX7219.Refresh();
delay(80);
}
}
/* SCROLL SOME INVERTED TEXT 2 TIMES BEFORE MOVING ON */
HCMAX7219.Invert(INVERTON);
for (Loopcounter = 0; Loopcounter <= 2; Loopcounter++)
{
for(Position=0; Position <= 64; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix("HELLO!! ", Position);
HCMAX7219.Refresh();
delay(80);
}
}
HCMAX7219.Invert(INVERTOFF);
/* SCROLL AND INTEGER NUMBER */
for(Position=0; Position <= 80; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix(-12345678, Position);
HCMAX7219.Refresh();
delay(80);
}
/* SCROLL AND INTEGER NUMBER WITH DECIMAL PLACE */
for(Position=0; Position <= 96; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix(-12345678, 2, Position);
HCMAX7219.Refresh();
delay(80);
}
}
The library files can be downloaded below:
Latest Version (0.5)
Older version (0.4)
Older version (0.3)
Older version 0.2