// 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
int c = 0;
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.
}
void SendSymbol(uint8_t symbolIndex) {
uint8_t* symbol = SYMBOLS[symbolIndex];
for (int i = 1; i < 9; i++)
SendData(i, symbol[i - 1]);
}
void SendSequence(uint8_t* seq) {
uint8_t symbolIndex = seq[c++];
if (c == sizeof(seq))
c = 0;
SendSymbol(symbolIndex);
}
void SendChar(char c, int ms = 0) {
uint8_t symbolIndex = CHAR2SYMBOL[c];
if(symbolIndex != 99)
SendSymbol(symbolIndex);
else
SendSymbol(NOSYMBOL);
if (ms > 0)
delay(ms);
}
void SendString(char* str, uint8_t len, int ms = 1000) {
char nextchar = str[c++];
if (c == len)
c = 0;
SendChar(nextchar, ms);
}
//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, SPC
//uint8_t sequence[] = { 10,52,52,48,41, 36, 34,58,49, 36}; // Apple Yum ....
char mystr[] = "Seneca College Rocks ";
void loop() {
// SendChar('1', 1000); // show and pause 1s
// SendChar('0', 1000);
// SendChar(' ', 1000);
// SendChar('A', 1000);
// SendChar('Z', 1000);
// SendChar(' ', 1000);
// SendChar('a', 1000);
// SendChar('z', 1000);
// SendChar(' ', 1000);
// SendChar('!', 1000); // no symbol, while show crossed box
//SendString("Hello World ", 12);
//SendString("Hello World ", 12, 2000); // twice as slow as default
//SendString(mystr, sizeof(mystr)-1);
SendString(mystr, sizeof(mystr)-1, 500); //twice as fast as default
}