This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.clock
258 lines (244 loc) · 7.27 KB
/
demo.clock
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
/*
* demo.tommyclock
*
* This demo is Tommy's clock.
*
*/
#include "main.h"
#define HOLD_FRAMES 0 // 5
int numFrames;
int seconds;
int minutes;
int hours;
int pm;
static void clear_display()
{
unsigned int col, row;
for (row = 0; row < 8; row++)
for (col = 0; col < 8; col++)
{
display_buffer[row][(col * COL_SIZE) + 0] = 0;
display_buffer[row][(col * COL_SIZE) + 1] = 0;
display_buffer[row][(col * COL_SIZE) + 2] = 0;
}
}
void setup(void)
{
// This code is invoked once to initialize the demo...
numFrames = 0;
seconds = 0;
minutes = 0;
hours = 0;
pm = 0;
}
void loop(void)
{
// This code is invoked once each time the LEDs are scanned...
int i;
if (numFrames > 0)
{
// Hold current image for some frames
numFrames--;
return;
}
numFrames = HOLD_FRAMES;
// Clear the display
clear_display();
// Blink center
if ((seconds & 1) != 0)
{
display_buffer[3][COL3 + RED] = FULL_INTENSITY;
display_buffer[3][COL4 + RED] = FULL_INTENSITY;
display_buffer[4][COL3 + RED] = FULL_INTENSITY;
display_buffer[4][COL4 + RED] = FULL_INTENSITY;
}
if (seconds <= 8)
{
for (i = 0; i < seconds; i++)
display_buffer[i][COL7 + GREEN] = FULL_INTENSITY;
}
else if (seconds <= 15)
{
for (i = 0; i < 8; i++)
display_buffer[i][COL7 + GREEN] = FULL_INTENSITY;
for (i = 0; i < seconds - 7; i++)
display_buffer[7][(7 - i) * COL_SIZE + GREEN] = FULL_INTENSITY;
}
else if (seconds <= 23)
{
for (i = 0; i < 8; i++)
display_buffer[i][COL7 + GREEN] = FULL_INTENSITY;
for (i = 1; i < 8; i++)
display_buffer[7][(7 - i) * COL_SIZE + GREEN] = FULL_INTENSITY;
for (i = 0; i < seconds - 15; i++)
display_buffer[i][COL7 + RED] = FULL_INTENSITY;
}
else if (seconds <= 30)
{
for (i = 0; i < 8; i++)
{
display_buffer[i][COL7 + RED] = FULL_INTENSITY;
display_buffer[i][COL7 + GREEN] = FULL_INTENSITY;
}
for (i = 1; i < 8; i++)
display_buffer[7][(7 - i) * COL_SIZE + GREEN] = FULL_INTENSITY;
for (i = 0; i < seconds - 23; i++)
display_buffer[7][(7 - i) * COL_SIZE + RED] = FULL_INTENSITY;
}
else if (seconds <= 38)
{
for (i = 0; i < 8; i++)
display_buffer[i][COL7 + RED] = FULL_INTENSITY;
for (i = seconds - 30; i < 8; i++)
display_buffer[i][COL7 + GREEN] = FULL_INTENSITY;
for (i = 1; i < 8; i++)
{
display_buffer[7][(7 - i) * COL_SIZE + RED] = FULL_INTENSITY;
display_buffer[7][(7 - i) * COL_SIZE + GREEN] = FULL_INTENSITY;
}
}
else if (seconds <= 45)
{
for (i = 0; i < 8; i++)
display_buffer[i][COL7 + RED] = FULL_INTENSITY;
for (i = 1; i < 8; i++)
display_buffer[7][(7 - i) * COL_SIZE + RED] = FULL_INTENSITY;
for (i = 0; i <= 45 - seconds; i++)
display_buffer[7][i * COL_SIZE + GREEN] = FULL_INTENSITY;
}
else if (seconds <= 53)
{
for (i = seconds - 45; i < 8; i++)
display_buffer[i][COL7 + RED] = FULL_INTENSITY;
for (i = 1; i < 8; i++)
display_buffer[7][(7 - i) * COL_SIZE + RED] = FULL_INTENSITY;
}
else
for (i = 0; i <= 60 - seconds; i++)
display_buffer[7][i * COL_SIZE + RED] = FULL_INTENSITY;
seconds++;
if (seconds > 59)
{
seconds = 0;
hours++;
if (hours > 11)
{
hours = 0;
if (pm == 0)
pm = 1;
else
pm = 0;
}
}
switch (hours)
{
case 0:
display_buffer[0][COL2 + RED] = FULL_INTENSITY;
display_buffer[0][COL4 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[0][COL2 + GREEN] = FULL_INTENSITY;
display_buffer[0][COL4 + GREEN] = FULL_INTENSITY;
}
break;
case 1:
display_buffer[0][COL4 + RED] = FULL_INTENSITY;
display_buffer[0][COL6 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[0][COL4 + GREEN] = FULL_INTENSITY;
display_buffer[0][COL6 + GREEN] = FULL_INTENSITY;
}
break;
case 2:
display_buffer[0][COL6 + RED] = FULL_INTENSITY;
display_buffer[2][COL6 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[0][COL6 + GREEN] = FULL_INTENSITY;
display_buffer[2][COL6 + GREEN] = FULL_INTENSITY;
}
break;
case 3:
display_buffer[2][COL6 + RED] = FULL_INTENSITY;
display_buffer[4][COL6 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[2][COL6 + GREEN] = FULL_INTENSITY;
display_buffer[4][COL6 + GREEN] = FULL_INTENSITY;
}
break;
case 4:
display_buffer[4][COL6 + RED] = FULL_INTENSITY;
display_buffer[6][COL6 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[4][COL6 + GREEN] = FULL_INTENSITY;
display_buffer[6][COL6 + GREEN] = FULL_INTENSITY;
}
break;
case 5:
display_buffer[6][COL6 + RED] = FULL_INTENSITY;
display_buffer[6][COL4 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[6][COL6 + GREEN] = FULL_INTENSITY;
display_buffer[6][COL4 + GREEN] = FULL_INTENSITY;
}
break;
case 6:
display_buffer[6][COL4 + RED] = FULL_INTENSITY;
display_buffer[6][COL2 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[6][COL4 + GREEN] = FULL_INTENSITY;
display_buffer[6][COL2 + GREEN] = FULL_INTENSITY;
}
break;
case 7:
display_buffer[6][COL2 + RED] = FULL_INTENSITY;
display_buffer[6][COL0 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[6][COL2 + GREEN] = FULL_INTENSITY;
display_buffer[6][COL0 + GREEN] = FULL_INTENSITY;
}
break;
case 8:
display_buffer[6][COL0 + RED] = FULL_INTENSITY;
display_buffer[4][COL0 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[6][COL0 + GREEN] = FULL_INTENSITY;
display_buffer[4][COL0 + GREEN] = FULL_INTENSITY;
}
break;
case 9:
display_buffer[4][COL0 + RED] = FULL_INTENSITY;
display_buffer[2][COL0 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[4][COL0 + GREEN] = FULL_INTENSITY;
display_buffer[2][COL0 + GREEN] = FULL_INTENSITY;
}
break;
case 10:
display_buffer[2][COL0 + RED] = FULL_INTENSITY;
display_buffer[0][COL0 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[2][COL0 + GREEN] = FULL_INTENSITY;
display_buffer[0][COL0 + GREEN] = FULL_INTENSITY;
}
break;
case 11:
display_buffer[0][COL0 + RED] = FULL_INTENSITY;
display_buffer[0][COL2 + RED] = FULL_INTENSITY;
if (pm)
{
display_buffer[0][COL0 + GREEN] = FULL_INTENSITY;
display_buffer[0][COL2 + GREEN] = FULL_INTENSITY;
}
break;
}
}