forked from nhatuan84/esp32-led-matrix
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLedMatrix.h
139 lines (115 loc) · 3.26 KB
/
LedMatrix.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <Arduino.h>
// max7219 registers
#define MAX7219_REG_NOOP 0x0
#define MAX7219_REG_DIGIT0 0x1
#define MAX7219_REG_DIGIT1 0x2
#define MAX7219_REG_DIGIT2 0x3
#define MAX7219_REG_DIGIT3 0x4
#define MAX7219_REG_DIGIT4 0x5
#define MAX7219_REG_DIGIT5 0x6
#define MAX7219_REG_DIGIT6 0x7
#define MAX7219_REG_DIGIT7 0x8
#define MAX7219_REG_DECODEMODE 0x9
#define MAX7219_REG_INTENSITY 0xA
#define MAX7219_REG_SCANLIMIT 0xB
#define MAX7219_REG_SHUTDOWN 0xC
#define MAX7219_REG_DISPLAYTEST 0xF
#define TEXT_ALIGN_LEFT 0 // Text is aligned to left side of the display
#define TEXT_ALIGN_LEFT_END 1 // Beginning of text is just outside the right end of the display
#define TEXT_ALIGN_RIGHT 2 // End of text is aligned to the right of the display
#define TEXT_ALIGN_RIGHT_END 3 // End of text is just outside the left side of the display
#define TEXT_ALIGN_CENTER 4 // Mid of text is just middle of the display
class LedMatrix {
public:
/**
* Constructor.
* numberOfDisplays: number of connected devices
* slaveSelectPin: CS (or SS) pin connected to your ESP8266
*/
LedMatrix(byte numberOfDisplays, byte slaveSelectPin);
/**
* Initializes the SPI interface
*/
void init();
/**
* Sets the intensity on all devices.
* intensity: 0-15
*/
void setIntensity(byte intensity);
/**
* Sets the text alignment.
* Default is TEXT_ALIGN_LEFT_END.
*
*/
void setTextAlignment(byte textAlignment);
/**
* Send a byte to a specific device.
*/
void sendByte (const byte device, const byte reg, const byte data);
/**
* Send a byte to all devices (convenience method).
*/
void sendByte (const byte reg, const byte data);
/**
* Turn on pixel at position (x,y).
*/
void setPixel(byte x, byte y);
/**
* Clear the frame buffer.
*/
void clear();
/**
* Draw the currently set text at the current offset.
*/
void drawText();
/**
* Set the current text.
*/
void setText(String text);
/**
* Set the text that will replace the current text after a complete scroll
* cycle.
*/
void setNextText(String nextText);
/**
* Get number of columns of Text (Pixel).
*/
int getTextLength();
/**
* Set a specific column with a byte value to the framebuffer.
*/
void setColumn(int column, byte value);
/**
* Writes the framebuffer to the displays.
*/
void commit();
/**
* Scroll the text to the right.
*/
void scrollTextRight();
/**
* Scroll the text to the left.
*/
void scrollTextLeft();
/**
* Oscilate the text between the two limits.
*/
void oscillateText();
/**
* Display is mounted 90 degree right.
*/
void setAlternateDisplayOrientation(byte x = 1);
private:
byte* cols;
String myText;
String myNextText;
int myTextLength = 0;
int myTextOffset = 1;
int myTextAlignmentOffset = 0;
int increment = -1;
byte myNumberOfDevices = 0;
byte mySlaveSelectPin = 0;
byte myTextAlignment = 1;
byte myDisplayOrientation = 0;
void calculateTextAlignmentOffset();
};