-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEDMatrix.h
151 lines (126 loc) · 4.42 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
140
141
142
143
144
145
146
147
148
149
150
151
#include "Position.h"
// controller for Adafruit 8x8 LED matrix using backpack
#define ROWS_PER_FRAME 8
#define MAX_FRAMES 16
#define COLUMS_PER_ROW 8
//
// some reasonable frame delay values for animations
//
#define VFRM_DLAY 160 // long delay between frames
#define LFRM_DLAY 100 // long delay between frames
#define MFRM_DLAY 80 // medium delay between frames
#define SFRM_DLAY 30 // short delay between frames
#define END_FRAMES 0 // no more frames
class LEDMatrix {
public:
static const byte DEFAULT_I2C_ADDR = 0x70;
static const byte BLINK_NONE = 0;
static const byte BLINK_2HZ = 2;
static const byte BLINK_1HZ = 4;
static const byte BLINK_HALFHZ = 5;
LEDMatrix();
LEDMatrix(byte I2CAddress);
//
// lower power consumption to extend battery life
//
void lowPowerMode();
//
// Clear display buffer
//
void clear();
//
// turn on display, blank it and set brigthness
//
void initializeDisplay(const byte brightness, const byte blinkType);
//
// draw a sequence of screens with sleep between each frame
//
// frame_timing - array of indicating how long to sleep between frames.
// an entry of zero indicates no more frames and decides how
// many frames will be processed by this function
//
// frames - two dimensional array of bitmapped data to draw
// the first index is the row 0 .. 8
// the second index is the frame number in the animation
//
// repititions - how many times to repeat the entire animation from first frame to last
//
//
// draw a sequence of screens with sleep between each frame while fading the brightness in and out
// uses multiple calls to drawAnimation while adjusting display brightness
//
// frame_timing - array of indicating how long to sleep between frames.
// an entry of zero indicates no more frames and decides how
// many frames will be processed by this function
//
// frames - two dimensional array of bitmapped data to draw
// the first index is the row 0 .. 8
// the second index is the frame number in the animation
//
// repititions - how many times to repeat the entire animation from first frame to last
//
// fadeStep - amount to increment/decrement display brightness level beteween animations
// the brightness goes from 0 to 15 and back so reasonable values here are from 1 to 5
//
// sleepWhenDone - millis to sleep when sequence is complete
//
//
// put display and gemma to sleep for extremely low power consumption
// wakeup happens when the button is pushed and the interrupt is triggered
// this function will not return until the button is pushed
void goToSleep();
//
// set the brightness level for the display
// level - value from 0 to 15 with 15 being the brightest
void setBrightness(const unsigned int level);
//
// turn on the oscillator in the backpack
void oscillatorOn();
//
// turn off the oscillator in the backpack
void oscillatorOff();
// send the display on command
// blinkType - one of the following values:
// BLINK_NONE
// BLINK_2HZ
// BLINK_1HZ
// BLINK_HALFHZ
void displayOn(const int blinkType);
//send the display off command
void displayOff();
void drawFrame(const uint8_t data[ROWS_PER_FRAME][MAX_FRAMES] PROGMEM, int frameIndex, Position* pos);
private:
int address;
//
//
//
uint8_t slideRow(const uint8_t rowData, Position* pos);
//
// send single byte command to LED matrix
//
void ledCmd(const uint8_t cmd);
//
// translate a byte of bitmapped pixels into an LED matrix command as follows:
// input bitmap bits = 7 6 5 4 3 2 1 0
// target LED bits = 7 0 1 2 3 4 5 6
//
// rowData - bitmapped representation of pixels to draw
// bit 7 is the leftmost pixel and bit 0 is the rightmost pixel
//
// returns - byte formatted for LED matrix
static uint8_t translateRow(const uint8_t rowData);
//
// begin writing pixel data to screan
//
void beginFrame();
//
// end writing pixel data to screen
//
void endFrame();
//
// draw one row of 8 pixels below the previously drawn row
// rowData - bitmapped representation of row
// bit 7 is the leftmost pixel and bit 0 is the right
//
void drawRow(const uint8_t rowData);
};