Try starting in the playground, “Interfacing with hardware”.
Learn how to read your sensors & have the data sent to the serial monitor as the 8 digits you want.
From there will be easy to write it to the MAX7221/7219 for display.
If you don’t use a libray, then you define a few addresses:
#include <SPI.h>
// SPI uses hardware Chip Select vs having device address
// 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
// replace these names with your digit names: left_tens, left_ones, left_tenths, left_C for example & same for the right side
#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
//write the data out to set it up
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 <--- Need this here before any SPI writes?
// 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, repeat for all 8 digits
// 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
// MAX7221, set up for normal use
// 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
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
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 ");
} // end void setup
Now in the loop section, have your code set the flag “update_time” to 1 when your display needs changing, this part of the code will see that and write the updated data out
void loop(){
// your code that reads the temps once a second or something
// and breaks it up into 6 digits
// if a digit change, set this flag:
update_time = 1;
// loop then continues and udpates the display here if needed
//****
// Time digits display update section
//*****
if (update_time == 1) // if = 1, a change was made and we are updating time in here
// otherwise, the 7221 keeps displaying the same thing
{
update_time = 0; // reset for the next pass thru
//combine minutes_tens with Decimal point: colon
if (minutes_tens == 0) { // for blanking - skip this if/else if want all digits displayed all the time
number_to_display = 0x0F;
}
else {
number_to_display = minutes_tens;
}
number_to_display = number_to_display | colon; // OR in the decimal point
digitalWrite(SS,LOW); // take the SS pin low to select the chip
SPI.transfer(minutes_tens_address); // select the Address,
SPI.transfer(number_to_display); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
// repeat this for the other digits
// where you need the decimal point on, set the decimal point bit high
} // end Score Update section
} // end void loop