The MAX7219 is set up to be driven from the SPI 'port'. Does that library use SPI?
If so, how do you have the SPI pins wired up?
13 is the arduino clock output
12 is the arduino data in line; not used here, the mAX7219 does output anything
11 is the arduino data out line
10 is the arduino SS/CS line to the MAX7219
If SPI port is being used, these pins are incorrect for a standard arduino:
LedControl lc=LedControl(12,11,10,1);
I use a MAX7221 in my application, and instead of a library I just wrote my own code:
#include <SPI.h>
int SS = 10; // need for SPI
// the digits the MAX7221 writes out
int minutes_tens=0; // decimalpoint = colon
int minutes_ones=0; // decimalpoint = left_priority
int seconds_tens=0; // decimalpoint = right_priority
int seconds_ones=0; // decimal point = swap
int leftscore_tens=0; // decimalpoint = left_yellow
int leftscore_ones=0; // decimalpoint = left_red
int rightscore_tens=0; // decimalpoint = right_red
int rightscore_ones=0; // decimalpoint = right_yellow
// addresses for the MAX7221, and the values/ranges to write in
#define DECODE_MODE 0x09 // write data 0xFF, Code B Decode for all digits
#define INTENSITY_ADDRESS 0x0A // 0x07 to start, half intensity. valid from 0x00 (min) to 0x0F (max)
#define SCANLIMIT_ADDRESS 0x0B // 0xFF, all 8 digits on
#define SHUTDOWN_ADDRESS 0x0C // 0x01, normal operation (0x01 = shutdown) - powers up in shutdown mode
#define DISPLAYTEST_ADDRESS 0x0F // 0x01 = all lights on full, 0x00 = normal ops
#define leftscore_tens_address 0x01 // digit 0, leftscore_tens+left_yellow, fill right hand byte with data to display
// data = 0-9, A='-', B='E', C='H', D='L', E='P', F=blank
#define leftscore_ones_address 0x02 // digit 1, leftscore_ones+right_yellow
#define rightscore_tens_address 0x03 // digit 2, rightscore_tens+right_red
#define rightscore_ones_address 0x04 // digit 3, rightscore_ones+right_yellow
#define minutes_tens_address 0x05 // digit 4, minutes_tens+colon
#define minutes_ones_address 0x06 // digit 5, minutes_ones+left_priority
#define seconds_tens_address 0x07 // digit 6, seconds_tens+right_priority
#define seconds_ones_address 0x08 // digit 7, seconds_ones+swap
void setup() // stuff that runs once before looping forever
{
// start up SPI to talk to the MAX7221
SPI.begin(); // nothing in () because we are the master
pinMode(SS, OUTPUT); // Slave Select for SPI
// MAX7221: write shutdown register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SHUTDOWN_ADDRESS); // select the Address,
SPI.transfer(0x00); // select the data, 0x00 = Outputs turned off
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
// Serial.println("shutdown register, dislays off");
// put known values into MAX7221 so doesn't have weird display when actually turned on
// 0x0F = blank digit
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(leftscore_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(leftscore_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(rightscore_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(rightscore_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(minutes_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(minutes_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(seconds_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(seconds_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
// MAX7221:
// write intensity register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(INTENSITY_ADDRESS); // select the Address,
SPI.transfer(intensity); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("intensity register ");
// write scanlimit register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SCANLIMIT_ADDRESS); // select the Address,
SPI.transfer(0xFF); // select the data - FF = all 8 digits <<< change this if you only use 3 digits
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("scanlimit register ");
// write decode register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DECODE_MODE); // select the Address,
SPI.transfer(0xFF); // select the data - FF = all 8 digits <<< change this if you only use 3 digits
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("decode register ");
//display test
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DISPLAYTEST_ADDRESS); // select the Address,
SPI.transfer(0x01); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("digit display test on ");
delay (100);
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DISPLAYTEST_ADDRESS); // select the Address,
SPI.transfer(0x00); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("digit display test off ");
delay (100);
// write shutdown register for normal display operations
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SHUTDOWN_ADDRESS); // select the Address,
SPI.transfer(0x01); // select the data, 0x01 = Normal Ops
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("shutdown register, displays on ");
My void loop() does a bunch of things - reads buttons, checks for serial messages, and updates the display.
When I make a change to a digit based on button presses or a serial message, I set a flag. The update display code checks that flag and sends an SPI message like this to update the registers.
You can do the same for each individual register, or just update all 3 if any one changes.
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(seconds_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip