-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.h
246 lines (233 loc) · 6.85 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
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
class Display
{
// Class Member Variables
// These are initialized at startup
int pinA;
int pinB;
int pinC;
int pinD;
int pinE;
int pinF;
int pinG;
int D1;
int D2;
int D3;
int D4;
// These maintain the current state
unsigned long previousMillis;
unsigned long digitMillis;
// Constructor - creates a Display
// and initializes the member variables and state
public:
int number;
Display(){}
Display(int A, int B, int C, int D, int E, int F, int G, int _D1, int _D2, int _D3, int _D4)
{
previousMillis = millis();
digitMillis = millis();
pinMode(A0, OUTPUT);
// setup pins bars
pinA = A;
pinB = B;
pinC = C;
pinD = D;
pinE = E;
pinF = F;
pinG = G;
D1 = _D1;
D2 = _D2;
D3 = _D3;
D4 = _D4;
number = 9876;
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
/*
* Column
*/
pinMode(A2, OUTPUT);
pinMode(9, OUTPUT);
}
void Update()
{
unsigned long currentMillis = millis();
// check to see if it's time to change the state of the LED
if(currentMillis - digitMillis == 3){
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(D4, LOW);
digitalWrite(A2, LOW);
digitalWrite(9, LOW);
}
int cnt = 4;
if((currentMillis - previousMillis == cnt))
{
digitalWrite(D1, HIGH);
if(number > 999){
shownumber((number / 1000) % 10);
} else{
shownumber(0);
}
digitMillis = currentMillis;
}
else if ((currentMillis - previousMillis == cnt + cnt))
{
digitalWrite(D2, HIGH);
if(number > 99){
shownumber((number / 100) % 10);
} else{
shownumber(0);
}
digitMillis = currentMillis;
}
else if ((currentMillis - previousMillis == cnt + cnt*2))
{
digitalWrite(D3, HIGH);
if(number > 9){
shownumber((number / 10) % 10);
} else{
shownumber(0);
}
digitMillis = currentMillis;
}
else if ((currentMillis - previousMillis == cnt + cnt*3))
{
digitalWrite(D4, HIGH);
shownumber(number % 10);
digitMillis = currentMillis;
}
else if (currentMillis - previousMillis > cnt + cnt*4)
{
digitalWrite(A2, HIGH);
digitalWrite(9, HIGH);
previousMillis = currentMillis;
digitMillis = currentMillis;
}
}
void shownumber(int n){
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
switch(n){
case 0:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
break;
case 1:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 2:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
case 3:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
case 4:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 5:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 6:
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 7:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
break;
case 8:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
case 9:
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
break;
default:
digitalWrite(pinA, HIGH);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
break;
}
}
};