-
Notifications
You must be signed in to change notification settings - Fork 6
/
DotMatrixBoard.cpp
49 lines (42 loc) · 1.22 KB
/
DotMatrixBoard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Common.h"
#include "DotMatrixBoard.h"
DotMatrixBoard::DotMatrixBoard(int x, int y) : Board(x, y) {
_numDevices = x / 8; // support only factors of 8
}
DotMatrixBoard::~DotMatrixBoard(void) {
if (_mx) delete _mx;
_mx = NULL;
}
void DotMatrixBoard::setPins(int8_t din, int8_t cs, int8_t clk) {
_din = din;
_cs = cs;
_clk = clk;
_mx = new MD_MAX72XX(MD_MAX72XX::FC16_HW, _cs, _numDevices);
_mx->begin();
_mx->control(MD_MAX72XX::INTENSITY, MAX_INTENSITY/2);
}
void DotMatrixBoard::print(void) {
_mx->control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
for (int i = 0; i < _x; i++) {
for (int j = 0; j < _y; j++) {
if (i >= _tx && i < _tx+4 && j >= _ty && j < _ty+4 && _active && _active->shape[i-_tx][j-_ty]) {
_mx->setPoint(j, i, _active->shape[i-_tx][j-_ty]);
}
else {
_mx->setPoint(j, i, _b[i][j]);
}
}
}
_mx->control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void DotMatrixBoard::testPrint(bool value) {
_mx->control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
for (int i = 0; i < _x; i++) {
for (int j = 0; j < _y; j++) {
_mx->setPoint(j, i, value);
}
}
_mx->control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}