-
Notifications
You must be signed in to change notification settings - Fork 0
/
DISPLAY.h
131 lines (110 loc) · 2.88 KB
/
DISPLAY.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
#define latch_Col 24
#define clock_Col 23
#define data_Col 25
#define toggle_Col 22
byte const row_pins[6] = { 16, 17, 18, 19, 20, 21 };
bool showing_page = LOW;
long unsigned _now_page = millis();
unsigned long scrolling_speed = 200;
long unsigned _now = millis();
// LED Matrix
#define MAX_CONCAT 99
#define MAX_CHAR 20
int column_data[34] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int _tick = 0;
int matrix_brightness = 0;
class Display {
private:
int index;
int scroller;
int scroller_temp;
int ticker;
void clear_concat() {
for (int i = 0; i < MAX_CONCAT; i++) {
concat_text[i] = 0;
}
}
public:
int display_control[NUM_LAYOUT] = { 0, 1, 4};
int text_len = 5;
// int text[MAX_CHAR] = {79, 80, 69, 78, 14, 67, 79, 78, 84, 82, 79, 76};
// int text[MAX_CHAR] = {96, 97,98, 99, 100, 101, 102, 103, 104};
int temp_text[MAX_CHAR];
int data_text[MAX_CHAR] = { 79, 80, 105, 67, 79 };
int page_text[MAX_CHAR] = { 48, 65, 71, 69, 0, 79 };
int concat_text[MAX_CONCAT];
void clear_text() {
for (int i = 0; i < MAX_CHAR; i++) {
data_text[i] = 0;
}
}
void build_text(int _text_len, int *text) {
index = 0;
scroller_temp = 0;
scroller = 0;
scrolled = LOW;
clear_concat();
// text_len = text_len;
if (_text_len < 8) index = (36 - (_text_len * 4)) / 2;
for (int i = 0; i < _text_len; i++) {
for (int j = 0; j < 3; j++) {
if (index < MAX_CONCAT) concat_text[index] = font_5x7[text[i]][j];
if (font_5x7[text[i]][j] != 0) index++;
}
index++;
}
}
bool scrolled = LOW;
void inc_scroll() {
scroller_temp++;
if (scroller_temp > 5 && index > MAX_CHAR && !scrolled) scroller++;
if (scroller > (index - 30)) {
scroller_temp = 0;
scroller = 0;
scrolled = HIGH;
}
}
void _set(int s, bool v) {
digitalWrite(s, v);
}
void _set_analog(int s, int v) {
analogWrite(s, v);
}
void tick(int s) {
_set(s, LOW);
_set(s, HIGH);
}
void show_char(int i) {
int temp = concat_text[i - 1 + scroller];
int data_col = column_data[i];
_set(data_Col, data_col);
_set(toggle_Col, HIGH);
// _set_analog(toggle_Col, 1050);
for (int j = 0; j < 8; j++) {
bool data_row = !(temp & (0x80));
if (7 - j < 6) _set(row_pins[7 - j], data_row);
temp <<= 1;
}
tick(latch_Col);
_set_analog(toggle_Col, matrix_brightness);
tick(clock_Col);
};
};
Display disp;
void Display_Handler()
{
_tick ++;
if (_tick == 34) _tick = 0;
disp.show_char(_tick);
}
void setup_display() {
pinMode(latch_Col, OUTPUT);
pinMode(clock_Col, OUTPUT);
pinMode(data_Col, OUTPUT);
pinMode(toggle_Col, OUTPUT);
for (int i = 0; i < 6; i++) {
pinMode(row_pins[i], OUTPUT);
}
int init_text[5] = { 79, 80, 105, 67, 79 };
disp.build_text(5, init_text);
}