-
Notifications
You must be signed in to change notification settings - Fork 10
/
MEOColorPhasing.cpp
224 lines (209 loc) · 6.51 KB
/
MEOColorPhasing.cpp
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
/*
G35: An Arduino library for GE Color Effects G-35 holiday lights.
Copyright © 2011 The G35 Authors. Use, modification, and distribution are
subject to the BSD license as described in the accompanying LICENSE file.
By Mike Tsao <http://github.com/sowbug>.
and Mark Ortiz
and Adafruit
See README for complete attributions.
*/
#include <MEOColorPhasing.h>
#define PI 3.14159265
MEOColorPhasing::MEOColorPhasing(MEOG35& g35, uint8_t pattern) : MEOLightProgram(g35, pattern), wait_(0), frequencyR_(0.06), frequencyG_(0.06), frequencyB_(0.06),
phaseR_(0), phaseG_(2*PI/3), phaseB_(4*PI/3), center_(8), width_(7), fStep_(0), pStep_(0), fForward_(true), turn_(0), pattern_(pattern), grnOff_(false), bluOff_(false), redOff_(false)
{
}
// neat rainbow phase 0, 2*PI/3, 4*PI/3 (120deg = 2PI/3, so 0, 120, 240)
uint32_t MEOColorPhasing::Do()
{
switch (pattern_ % 14)
{
case 0: //Wavey pastels
phaseR_ = 0;
phaseG_ = 2*PI/3;
phaseB_ = 4*PI/3;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 1: // subtly changing pastels
phaseR_ = 0;
phaseG_ = (2*PI/360) * pStep_;
phaseB_ = (4*PI/360) * pStep_;
frequencyR_ = 1.666;
frequencyG_ = 2.666;
frequencyB_ = 3.666;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 2: //White twinkle
phaseR_ = pStep_;
phaseG_ = pStep_;
phaseB_ = pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 3: //Red/Cyan change twinkle
phaseR_ = 0;
phaseG_ = pStep_;
phaseB_ = pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 4: //Blue/Yellow change twinkle
phaseR_ = pStep_;
phaseG_ = 0;
phaseB_ = pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 5: //Green/Magenta change twinkle
phaseR_ = pStep_;
phaseG_ = pStep_;
phaseB_ = 0;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 6: //Red twinkle
phaseR_ = 0;
phaseG_ = pStep_;
phaseB_ = pStep_;
frequencyR_ = 0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 7: //Green twinkle
phaseR_ = pStep_;
phaseG_ = 0;
phaseB_ = pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = 0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 8: //Blue twinkle
phaseR_ = pStep_;
phaseG_ = pStep_;
phaseB_ = 0;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = 0;
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 9: //Evolving pastel wave
switch (turn_ % 6)
{
case 0:
case 1:
phaseR_ = 0;
phaseG_ = (2*PI/360) * pStep_;
phaseB_ = (4*PI/360) * pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
break;
case 2:
case 3:
phaseG_ = 0;
phaseB_ = (2*PI/360) * pStep_;
phaseR_ = (4*PI/360) * pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
break;
case 4:
case 5:
phaseB_ = 0;
phaseR_ = (2*PI/360) * pStep_;
phaseG_ = (4*PI/360) * pStep_;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
break;
}
redOff_ = false; grnOff_ = false; bluOff_ = false;
break;
case 10: //magenta twinkle
phaseR_ = 0;
phaseG_ = 2*PI/3;
phaseB_ = 4*PI/3;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = true; bluOff_ = false;
break;
case 11: //yellow twinkle
phaseR_ = 0;
phaseG_ = 2*PI/3;
phaseB_ = 4*PI/3;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = false; grnOff_ = false; bluOff_ = true;
break;
case 12: //cyan twinkle
phaseR_ = 0;
phaseG_ = 2*PI/3;
phaseB_ = 4*PI/3;
frequencyR_ = float(fStep_) / 100.0;
frequencyG_ = float(fStep_) / 100.0;
frequencyB_ = float(fStep_) / 100.0;
redOff_ = true; grnOff_ = false; bluOff_ = false;
break;
default: //nothing - a still pastel rainbow
;
}
for (int i=0; i < light_count_; i++)
{
int red = sin(frequencyR_*i + phaseR_) * width_ + center_;
int grn = sin(frequencyG_*i + phaseG_) * width_ + center_;
int blu = sin(frequencyB_*i + phaseB_) * width_ + center_;
if (redOff_)
{
red = 0;
}
if (grnOff_)
{
grn = 0;
}
if (bluOff_)
{
blu = 0;
}
g35_.fill_color(i, 1, MEOG35::MAX_INTENSITY, COLOR(red, grn, blu));
}
//set direction: 1 2 .. 98 99 98 .. 2 1
if (fStep_ == 100)
{
fForward_ = false;
}
if (fStep_ == -1)
{
fForward_ = true;
turn_++;
}
if (fForward_)
{
fStep_++;
}
if (!fForward_)
{
fStep_--;
}
pStep_++;
if (pStep_ == 360)
{
pStep_ = 0;
}
delay(wait_);
return bulb_frame_;
}