This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment_display.h
280 lines (261 loc) · 5.63 KB
/
segment_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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// segment_display.h
#ifndef SEGMENT_DISPLAY_H
#define SEGMENT_DISPLAY_H
#include <config.h>
void print_1digit();
void print_2digit();
void print_3digit();
void print_4digit();
void print_err();
void print_seg_digit(const unsigned char);
void seg_print_minus();
void seg_print_dot();
void seg_print_0();
void seg_print_1();
void seg_print_2();
void seg_print_3();
void seg_print_4();
void seg_print_5();
void seg_print_6();
void seg_print_7();
void seg_print_8();
void seg_print_9();
void seg_print_e();
void seg_print_r();
void on_digit_slot(const unsigned char);
void off_all_digit_slots();
const int MAX_DIGIT_SIGN = 4;
const int MAX_DECEMAL_SIGN = 1;
// turn on slots
void on_digit_slot(const unsigned char n) {
switch(n) {
case 4: print_4digit();
break;
case 3: print_3digit();
break;
case 2: print_2digit();
break;
case 1: print_1digit();
break;
default: print_err();
return;
}
}
void print_err() {
print_3digit();
seg_print_e();
print_2digit();
seg_print_r();
print_1digit();
seg_print_r();
Serial.println("ERROR");
}
void off_all_digit_slots() {
digitalWrite(digit_1, HIGH);
digitalWrite(digit_2, HIGH);
digitalWrite(digit_3, HIGH);
digitalWrite(digit_4, HIGH);
}
void print_1digit() {
digitalWrite(digit_1, LOW);
digitalWrite(digit_2, HIGH);
digitalWrite(digit_3, HIGH);
digitalWrite(digit_4, HIGH);
}
void print_2digit() {
digitalWrite(digit_1, HIGH);
digitalWrite(digit_2, LOW);
digitalWrite(digit_3, HIGH);
digitalWrite(digit_4, HIGH);
}
void print_3digit() {
digitalWrite(digit_1, HIGH);
digitalWrite(digit_2, HIGH);
digitalWrite(digit_3, LOW);
digitalWrite(digit_4, HIGH);
}
void print_4digit() {
digitalWrite(digit_1, HIGH);
digitalWrite(digit_2, HIGH);
digitalWrite(digit_3, HIGH);
digitalWrite(digit_4, LOW);
}
void print_seg_digit(const unsigned char n) {
switch(n) {
case 1: seg_print_1();
break;
case 2: seg_print_2();
break;
case 3: seg_print_3();
break;
case 4: seg_print_4();
break;
case 5: seg_print_5();
break;
case 6: seg_print_6();
break;
case 7: seg_print_7();
break;
case 8: seg_print_8();
break;
case 9: seg_print_9();
break;
default: seg_print_0();
break;
}
}
void seg_print_dot() {
digitalWrite(seg_g, LOW);
digitalWrite(seg_a, LOW);
digitalWrite(seg_b, LOW);
digitalWrite(seg_c, LOW);
digitalWrite(seg_d, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(dot, HIGH);
delay(3);
}
void seg_print_minus() {
digitalWrite(seg_g, HIGH);
digitalWrite(seg_a, LOW);
digitalWrite(seg_b, LOW);
digitalWrite(seg_c, LOW);
digitalWrite(seg_d, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(dot, LOW);
delay(7);
}
void seg_print_0() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_e, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_1() {
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_a, LOW);
digitalWrite(seg_d, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(seg_g, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_2() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_e, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_c, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_3() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_e, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_4() {
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_a, LOW);
digitalWrite(seg_d, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_5() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_b, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_6() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_e, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_b, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_7() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, LOW);
digitalWrite(seg_e, LOW);
digitalWrite(seg_f, LOW);
digitalWrite(seg_g, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_8() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_e, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_9() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, HIGH);
digitalWrite(seg_c, HIGH);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_e, LOW);
digitalWrite(dot, LOW);
delay(3);
}
void seg_print_e() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, LOW);
digitalWrite(seg_c, LOW);
digitalWrite(seg_d, HIGH);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, HIGH);
digitalWrite(seg_e, HIGH);
digitalWrite(dot, LOW);
delay(5);
}
void seg_print_r() {
digitalWrite(seg_a, HIGH);
digitalWrite(seg_b, LOW);
digitalWrite(seg_c, LOW);
digitalWrite(seg_d, LOW);
digitalWrite(seg_f, HIGH);
digitalWrite(seg_g, LOW);
digitalWrite(seg_e, HIGH);
digitalWrite(dot, LOW);
delay(5);
}
#endif // SEGMENT_DISPLAY_H