-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlooped_effects.ino
222 lines (175 loc) · 4.38 KB
/
looped_effects.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include <Adafruit_NeoPixel.h>
const int N_PIN = 1; // Gemma data pin
const int N_PXS = 16; // Loop size
uint8_t i;
uint16_t color, style;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PXS, N_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize all pixels to 'off'
strip.begin();
strip.show();
//Serial.begin(9600);
// hope there is enough variation in instruction timing
// to generate a decent random seed
randomSeed(analogRead(1) + millis());
for (i = 0; i < random(256); i++) {i = random(256);}
color = strip.Color(random(255), random(255), random(255));
style = random(5); // 1 = Wrap
// 2 = Pulse
// 3 = Heartbeat
// 4 = Four-way
// 5 = Two-Way
i = 0;
}
void loop() {
switch (style) {
case 1: // Wrap around clockwise
pxl_wrap_cw(i, 5, color);
delay(64);
if (i >= N_PXS) {i = -1;}
break;
case 2: // Pulse
pxl_pulse(16, color);
break;
case 3: // Heartbeat (double pulse)
pxl_pulse(24, color);
pxl_pulse(24, color);
delay(200);
break;
case 4: // Four-way rotate clockwise
pxl_x4(i, color);
delay(64);
if (i >= 4) { i = -1; }
break;
case 5: // Two-way rotate clockwise
pxl_x2(i, color);
delay(128);
if (i >= 8) {i = -1;}
break;
// case 9: // Trail :: todo get fade corrected
// pxl_trail_cw(i, color, 5); // Red
// delay(50);
//
// if (i >= N_PXS) {i = -1;}
// break;
default:
break;
}
i++;
}
// -------------------------------------
void pxl_blank () {
int16_t i=0;
// turn off all pixels
for (i=0; i<=N_PXS; i++){
strip.setPixelColor(i, 0);
}
}
// -------------------------------------
void pxl_wrap_cw(uint8_t p, uint8_t s, uint16_t c) {
pxl_blank();
// turn on p thru p + s
for (uint8_t i = p; i < (p + s); i++) {
if (i >= N_PXS){
strip.setPixelColor((i - N_PXS), c);
} else {
strip.setPixelColor(i, c);
}
}
strip.show();
}
// -------------------------------------
void pxl_pulse (uint8_t s, uint16_t c) {
for (uint8_t i=0; i<=N_PXS; i++){
strip.setPixelColor(i, c);
}
// full off
strip.setBrightness(1);
strip.show();
// run up
for (i=1; i< (256 - s); i += s) {
strip.setBrightness(i);
strip.show();
delay(50);
}
// full on
strip.setBrightness(255);
strip.show();
// run down
for (i=255; i >= s; i -= s) {
strip.setBrightness(i);
strip.show();
delay(50);
}
// full off
strip.setBrightness(1);
strip.show();
}
// -------------------------------------
void pxl_x4 (uint8_t p, int16_t c) {
pxl_blank();
strip.show();
//Serial.println(p);
// works because 0 < p < 5. Effect 1 px wide
strip.setPixelColor(p, c);
strip.setPixelColor(p + 4, c);
strip.setPixelColor(p + 8, c);
strip.setPixelColor(p + 12, c);
strip.show();
}
// -------------------------------------
void pxl_x2 (uint8_t p, int16_t c) {
uint8_t q;
pxl_blank();
// work when 0 < p < 9. Effect three px wide
strip.setPixelColor(p, c);
strip.setPixelColor(p + 1, c);
strip.setPixelColor(p + 2, c);
q=p+8;
if (q >= N_PXS) {q = (p + 8) - N_PXS;}
strip.setPixelColor(q, c);
q=p+9;
if (q >= N_PXS) {q = (p + 9) - N_PXS;}
strip.setPixelColor(q, c);
q=p+10;
if (q >= N_PXS) {q = (p + 10) - N_PXS;}
strip.setPixelColor(q, c);
strip.show();
}
// -------------------------------------
/*
void pxl_wrap_ccw(uint8_t p, uint32_t c, uint8_t s) {
pxl_blank();
// turn on p thru p + s
for (uint8_t i = p; i > (p - s); i--) {
if (i < 1){
strip.setPixelColor((N_PXS + i), c);
} else {
strip.setPixelColor(i, c);
}
}
strip.show();
}
*/
// -------------------------------------
/*
void pxl_trail_cw(uint8_t p, int8_t c, uint8_t s) {
int16_t i,j=0;
pxl_blank();
j=0;
// turn on p thru p + s
for (i = p; i < (p + s); i++) {
j++;
//if (r - (j * 32) > 0) { r = r - (j * 32); } else { r = 0; }
//if (g - (j * 32) > 0) { g = g - (j * 32); } else { g = 0; }
//if (b - (j * 32) > 0) { b = b - (j * 32); } else { b = 0; }
c=strip.Color(r,g,b); // fading each pixel by 16
if (i >= N_PXS){
strip.setPixelColor((i - N_PXS), c);
} else {
strip.setPixelColor(i, c);
}
}
strip.show();
}
*/