-
Notifications
You must be signed in to change notification settings - Fork 1
/
LEDMatrix.cpp
123 lines (103 loc) · 2.35 KB
/
LEDMatrix.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "LEDMatrix.h"
// Headers for Adafruit LED Matric Panel
#include <RGBmatrixPanel.h>
#include <gamma.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
extern RGBmatrixPanel LEDBoard;
LedMatrixClass::LedMatrixClass(int h, int w)
{
colorRed = colorGreen = colorBlue = 0;
}
/*
Set an individual pixel in the matrix display
rw, cl - row/column for pixel
co - color specification
brt - brightness specification
*/
void LedMatrixClass::setPixel(int rw, int cl)
{
LEDBoard.drawPixel(cl, rw, LEDBoard.Color333(colorRed, colorGreen, colorBlue));
return;
}
/*
Turn off a pixel in the display.
*/
void LedMatrixClass::clearPixel(int r, int c)
{
LEDBoard.drawPixel(c, r, LEDBoard.Color333(0, 0, 0));
return;
}
/*
Place a hex digit character on the matrix
cd - ClockDigit class instance
r,c - Row/column for the digit
co - color value
br - brightness value
*/
void LedMatrixClass::placeChar(ClockDigitClass *cd, int r, int c)
{
int crows = cd->getDisplayRows();
int ccols = cd->getDisplayColumns();
// Since each char is a 16-bit value, the MSB's are unused on many of the symbols
// Let's figure out how many are unused
int startBit = 16 - (crows*ccols);
for (int i = 0; i < crows; ++i)
{
for (int j = 0; j < ccols; ++j)
{
if (cd->getBitValue((i*ccols) + j + startBit) != 0)
setPixel(r + i, c + j);
else
clearPixel(r + i, c + j);
}
}
return;
}
/*
Place a row representing a binary number on the matrix
b - value to convert to binary representation
r, c - row/col in matrix
d - digits (columns) to use for binary number
co - color value
br - brightness value
*/
void LedMatrixClass::placeBinary(int b, int r, int c, int p)
{
int rtmp, gtmp, btmp;
for (int i = 0; i < p; ++i) // only need 'p' LSB from number
{
if (b & (0x01 << i))
setPixel(r, c + p - 1 - i);
else
clearPixel(r, c + p - 1 - i);
}
return;
}
void LedMatrixClass::setColor(int r, int g, int b)
{
colorRed = r;
colorGreen = g;
colorBlue = b;
return ;
}
void LedMatrixClass::clearScreen()
{
LEDBoard.fillScreen(LEDBoard.Color333(0, 0, 0));
}
void LedMatrixClass::fillScreen()
{
LEDBoard.fillScreen(LEDBoard.Color333(7, 7, 7));
}
void LedMatrixClass::saveColor()
{
saveColorRed = colorRed;
saveColorGreen = colorGreen;
saveColorBlue = colorBlue;
}
void LedMatrixClass::restoreColor()
{
colorRed = saveColorRed;
colorGreen = saveColorGreen;
colorBlue = saveColorBlue;
}