Amazing. I might have messed up MOSI and MISO when trying SPI previously. Seem to remember favoring pin 12. But why doesn't shiftOut work? The datasheet explicitly says that MAX7219 does not support SPI, yet not using SPI does not work. :S
Here's code I ran switching between decode mode 1 and outputing "digit", or decode mode 0 and blinking all using "current".
Thanks all for patience and good advice!
Now I can go back to the original intention of controlling several multicolor leds with three maxes. ![]()
PS. I'm now running with a 50K resistor since the datasheet explicitly mentions running less than 4 digits with anything less is not recommended. https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf - page 10, "Selecting Rset resistor".
#include <SPI.h>
byte data = 12;
byte clk = 13;
byte latch = 10;
byte status = 13;
long lastSwap = 0;
byte current = 0x0;
byte digit = 0;
byte max_noop = 0x00;
byte max_d0 = 0x01;
byte max_d1 = 0x02;
byte max_d2 = 0x03;
byte max_d3 = 0x04;
byte max_d4 = 0x05;
byte max_d5 = 0x06;
byte max_d6 = 0x07;
byte max_d7 = 0x08;
byte max_decode_mode = 0x09;
byte max_intensity = 0x0A;
byte max_scan_limit = 0x0B;
byte max_shutdown = 0x0C;
byte max_test = 0x0F;
void output(byte address, byte data) {
digitalWrite(latch, LOW);
SPI.transfer(address);
SPI.transfer(data);
digitalWrite(latch, HIGH);
digitalWrite(latch, LOW);
}
void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(data, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(status, OUTPUT);
output(max_shutdown, 0x01);
output(max_test, 0x00);
output(max_decode_mode, 0x00);
output(max_intensity, 0x08);
output(max_scan_limit, 0x01);
}
void loop() {
if (millis() - lastSwap > 1000) {
current = current == 0x0 ? 0xFF : 0x0;
digit = (digit + 1) % 10;
lastSwap = millis();
Serial.println(current);
}
output(max_d0, current);
}