-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClock.ino
199 lines (186 loc) · 4.54 KB
/
Clock.ino
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
int segA = 1;
int segB = 2;
int segC = 3;
int segD = 4;
int segE = 5;
int segF = 6;
int segG = 7;
int segP = 8;
int dig1 = 10;
int dig2 = 11;
int dig3 = 12;
int dig4 = 13;
int relay = 9;
int elapsed = millis() / 1000;
void showNumber(byte num) {
switch (num) {
case 0:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
case 1:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 2:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 3:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 4:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 5:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 6:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 7:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 8:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 9:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
default:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
}
}
void selectDigits(byte dig) {
if (dig & 1)
digitalWrite(dig1, LOW);
else
digitalWrite(dig1, HIGH);
if (dig & 2)
digitalWrite(dig2, LOW);
else
digitalWrite(dig2, HIGH);
if (dig & 4)
digitalWrite(dig3, LOW);
else
digitalWrite(dig3, HIGH);
if (dig & 8)
digitalWrite(dig4, LOW);
else
digitalWrite(dig4, HIGH);
}
void setup() {
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(segP, OUTPUT);
pinMode(dig1, OUTPUT);
pinMode(dig2, OUTPUT);
pinMode(dig3, OUTPUT);
pinMode(dig4, OUTPUT);
pinMode(relay, OUTPUT);
}
void loop() {
int current = elapsed;
int minutes = current / 60;
int seconds = current % 60;
int hours = minutes / 60 % 24;
int refresh = 5000;
// byte d1 = minutes % 60 / 10;
// byte d2 = minutes % 10;
// byte d3 = seconds / 10;
// byte d4 = seconds % 10;
byte d1 = (24 - hours) / 10;
byte d2 = (24 - hours) % 10 - 1;
byte d3 = (60 - minutes % 60) / 10 - 1;
byte d4 = 9 - minutes % 10;
bool sp = current & 1 == 1 ? HIGH : LOW;
while (current == elapsed) {
selectDigits(1);
showNumber(d1);
digitalWrite(segP, LOW);
delayMicroseconds(refresh);
selectDigits(2);
showNumber(d2);
digitalWrite(segP, sp);
delayMicroseconds(refresh);
selectDigits(4);
showNumber(d3);
digitalWrite(segP, LOW);
delayMicroseconds(refresh);
selectDigits(8);
showNumber(d4);
digitalWrite(segP, LOW);
delayMicroseconds(refresh);
elapsed = millis() / 1000;
}
digitalWrite(relay, sp);
}