// original code
// https://projecthub.arduino.cc/mdraber/controlling-8x8-dot-matrix-with-max7219-and-arduino-0c417a
#include <SPI.h>
#define CS 7
#include "Helpers.h"
#include "Symbols.h"
// MAX7219 Control registers
#define DECODE_MODE 9
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUTDOWN 0x0C
#define DISPLAY_TEST 0x0F
void SendData(uint8_t address, uint8_t value) {
digitalWrite(CS, LOW); // Start transfer, select chip
SPI.transfer(address); // Send address.
SPI.transfer(reverse[value]); // Send the value.
digitalWrite(CS, HIGH); // Finish transfer, unselect chip
}
void setup() {
pinMode(CS, OUTPUT);
SPI.setBitOrder(MSBFIRST); // Most significant bit first
SPI.begin(); // Start SPI
SendData(DISPLAY_TEST, 0x01); // Run test - All LED segments lit.
delay(1000);
SendData(DISPLAY_TEST, 0x00); // Finish test mode.
SendData(DECODE_MODE, 0x00); // Disable BCD mode.
SendData(INTENSITY, 0x0e); // Use lowest intensity.
SendData(SCAN_LIMIT, 0x0f); // Scan all digits.
SendData(SHUTDOWN, 0x01); // Turn on chip.
}
//uint8_t sequence[] = { 0,1,2,3,4,5,6,7,8,9 }; // all digits
//uint8_t sequence[] = { 10,11,12, /* ... */ 33,34,35 }; // upper case ABCXYZ
//uint8_t sequence[] = { 37,38,39, /* ... */ 60,61,62 }; // upper case abcxyz
// a, p, p, l, e, SPC, Y, u, m, m
uint8_t sequence[] = { 10,52,52,48,41, 36, 34,58,49,49 }; // Apple Yumm
int c = 0;
void loop() {
uint8_t symbolIndex = sequence[c++];
if (c == sizeof(sequence))
c = 0;
uint8_t* symbol = SYMBOLS[symbolIndex];
for (int i = 1; i < 9; i++)
SendData(i, symbol[i - 1]);
delay(1000);
}