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
/
Copy pathdemo.fader
166 lines (148 loc) · 2.8 KB
/
demo.fader
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
/*
* demo.fader
*
* This demo fades between high and low intensities.
*
*/
#ifndef DEMO_H_
#define DEMO_H_
#define DEMO
#define HOLD_FRAMES 0
int numFrames;
#define PAUSE 20
unsigned int color;
unsigned int index;
void setup(void)
{
// This code is invoked once to initialize the demo...
numFrames = 0;
color = 0;
index = 0;
}
void loop(void)
{
// This code is invoked once each time the LEDs are scanned...
unsigned char new_blue;
unsigned char new_green;
unsigned char new_red;
unsigned int col;
unsigned int row;
unsigned int x;
unsigned int new_intensity;
if (numFrames > 0)
{
// Hold current image for some frames
numFrames--;
return;
}
numFrames = HOLD_FRAMES;
if (index == 0)
{
// Next color
color++;
if (color > 7)
color = 1;
index = (FULL_INTENSITY - 1) * 2 + PAUSE * 3;
}
if ((index > (FULL_INTENSITY - 1) * 2 + PAUSE * 2) || (index <= PAUSE))
// Start off and end dim
new_intensity = 1;
else if (index > (FULL_INTENSITY - 1) + PAUSE * 2)
// Fade up
new_intensity = (FULL_INTENSITY - 1) * 2 + PAUSE * 2 - index + 1;
else if (index > (FULL_INTENSITY - 1) + PAUSE)
// Full brightness
new_intensity = FULL_INTENSITY;
else
// Fade down
new_intensity = index - PAUSE + 1;
index--;
if (color & 1)
new_red = new_intensity;
else
new_red = 0;
if (color & 2)
new_green = new_intensity;
else
new_green = 0;
if (color & 4)
new_blue = new_intensity;
else
new_blue = 0;
for (row = 0; row < 8; row++)
{
// Set up left band at lowest on intensity
x = row * 8 * 3;
if (new_red)
{
display_buffer[x] = 1;
display_buffer[x+3] = 1;
}
else
{
display_buffer[x] = 0;
display_buffer[x+3] = 0;
}
if (new_green)
{
display_buffer[x+1] = 1;
display_buffer[x+4] = 1;
}
else
{
display_buffer[x+1] = 0;
display_buffer[x+4] = 0;
}
if (new_blue)
{
display_buffer[x+2] = 1;
display_buffer[x+5] = 1;
}
else
{
display_buffer[x+2] = 0;
display_buffer[x+5] = 0;
}
// Set up the middle
for (col = 2; col < 6; col++)
{
x = (row * 8 + col) * 3;
display_buffer[x] = new_red;
display_buffer[x+1] = new_green;
display_buffer[x+2] = new_blue;
}
// Set up right band at highest on intensity
x = (row * 8 + 6) * 3;
if (new_red)
{
display_buffer[x] = FULL_INTENSITY;
display_buffer[x+3] = FULL_INTENSITY;
}
else
{
display_buffer[x] = 0;
display_buffer[x+3] = 0;
}
if (new_green)
{
display_buffer[x+1] = FULL_INTENSITY;
display_buffer[x+4] = FULL_INTENSITY;
}
else
{
display_buffer[x+1] = 0;
display_buffer[x+4] = 0;
}
if (new_blue)
{
display_buffer[x+2] = FULL_INTENSITY;
display_buffer[x+5] = FULL_INTENSITY;
}
else
{
display_buffer[x+2] = 0;
display_buffer[x+5] = 0;
}
}
}
#endif /* DEMO_H_ */