-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsymbols.cpp
More file actions
47 lines (36 loc) · 1.35 KB
/
symbols.cpp
File metadata and controls
47 lines (36 loc) · 1.35 KB
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
#include "symbols.h"
void drawSymbol(LedControl& lc, const prog_uint8_t symbol[], int x_offset) {
byte width = pgm_read_byte (&symbol[7]); // symbol width is coded in the last array element
for (byte r=0; r<7; ++r) {
byte data = pgm_read_byte (&symbol[r]); // fetch data from program memory
for (byte c=0; c<width; ++c) {
if (data & (1<<(6-c))) {
lc.setLed(0,r,c+x_offset,true);
} else {
//lc.setLed(0,r,c-x_offset,false);
}
}
}
}
void drawSymbols(LedControl& lc, const prog_uint8_t** symbols, int n_symbols, int x_offset) {
int totalTextWidth = 0;
for (int i=0; i<n_symbols; ++i) {
const prog_uint8_t* symbol = symbols[i];
byte w = pgm_read_byte (&symbol[7]);
drawSymbol(lc, symbol, x_offset+totalTextWidth);
totalTextWidth += w + 1; // Leave 1px space between symbols
}
}
void scrollSymbols(LedControl& lc, const prog_uint8_t** symbols, int n_symbols, int n_delay) {
int total_w = 0;
for (int i=0; i<n_symbols; ++i) {
const prog_uint8_t* symbol = symbols[i];
byte w = pgm_read_byte (&symbol[7]);
total_w += w + 1; // Leave 1px space between symbols
}
for (int i=7; i>=-(total_w); --i) {
drawSymbols(lc, symbols, n_symbols, i);
delay(n_delay);
lc.clearDisplay(0);
}
}