forked from jjhtpc/Photon-RGB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoton RGB Template firmware
257 lines (208 loc) · 5.76 KB
/
Photon RGB Template firmware
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
/*
* hook up your pixels and all of the pixel types that are supported.
*
*/
#include "application.h"
#include "neopixel.h"
#include "math.h"
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 88
#define PIXEL_TYPE WS2812B
#define brightness
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int r = 0;
int g = 0;
int b = 0;
int rmap = 0;
int gmap = 0 ;
int bmap = 0;
void setup(){
RGB.control(true);
RGB.color(0, 0, 0);
strip.begin();
strip.show();
Particle.function("led", led);
Particle.function("dim", dim);
Particle.variable("checkStatus1", "off");
Particle.variable("r", &r);
Particle.variable("b", &g);
Particle.variable("g", &b);
Particle.variable("rmap", &rmap);
Particle.variable("gmap", &gmap);
Particle.variable("bmap", &bmap);
}
void loop()
{
}
int led(String command){
if(command == "0"){
colorAll(strip.Color(0,0,0), 50);
Particle.variable("checkStatus1", "off");
}
else if(command == "1"){
colorAll(strip.Color(255, 180, 40), 50);
rmap = 255;
gmap = 180;
bmap = 40;
Particle.variable("checkStatus1", "on");
}
else if(command == "2"){
colorAll(strip.Color(255,0,0), 50);
rmap = 255;
gmap = 0;
bmap = 0;
Particle.variable("checkStatus1", "on");
}
else if(command == "3") {
colorWipe(strip.Color(120,80,20), 50);
Particle.variable("checkStatus1", "on");
}
else if(command == "4"){
colorWipe(strip.Color(30, 20, 5), 50);
brightness(1);
Particle.variable("checkStatus1", "on");
}
else if(command == "5"){
GoND(50,11,40);//30 sets, 8 pixels wide, 50us delay
colorWipe(strip.Color(120,80,20), 50);
Particle.variable("checkStatus1", "on");
}
else if(command == "6"){
GoBears(50,8,40);//30 sets, 8 pixels wide, 50us delay
colorWipe(strip.Color(120,80,20), 50);
Particle.variable("checkStatus1", "on");
}
else {
String aux1 = getValue(command, ',', 0);
String aux2 = getValue(command, ',', 1);
String aux3 = getValue(command, ',', 2);
int r = atoi(aux1.c_str());
int g = atoi(aux2.c_str());
int b = atoi(aux3.c_str());
colorAll(strip.Color(r,g,b), 50);
rmap = r;
gmap = g;
bmap = b;
Particle.variable("checkStatus1", "on");
}
}
int dim(String command){
int command1 = command.toInt();
r = map(command1,0,100,0,rmap);
g = map(command1,0,100,0,gmap);
b = map(command1,0,100,0,bmap);
colorAll(strip.Color(r,g,b), 50);
}
// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint8_t wait) {
uint16_t i;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(wait);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
void CandyCane (int sets,int width,int wait) {
int L;
for(int j=0;j<(sets*width);j++) {
for(int i=0;i< strip.numPixels();i++) {
L=strip.numPixels()-i-1;
if ( ((i+j) % (width*2) )<width)
strip.setPixelColor(L,255,0,0);
else
strip.setPixelColor(L,0,255,0);
};
strip.show();
delay(wait);
}
}
void StaticCandyCane (int width) {
int L;
for(int i=0;i< strip.numPixels();) {
L=strip.numPixels()-i-1;
if ( ((i) % (width*2) )<width)
strip.setPixelColor(L,255,0,0);
else
strip.setPixelColor(L,0,255,0);
};
strip.show();
}
void GoND (int sets,int width,int wait) {
int L;
for(int j=0;j<(sets*width);j++) {
for(int i=0;i< strip.numPixels();i++) {
L=strip.numPixels()-i-1;
if ( ((i+j) % (width*2) )<width)
strip.setPixelColor(L,0,0,102);
else
strip.setPixelColor(L,255,153,0);
};
strip.show();
delay(wait);
}
}
void GoBears (int sets,int width,int wait) {
int L;
for(int j=0;j<(sets*width);j++) {
for(int i=0;i< strip.numPixels();i++) {
L=strip.numPixels()-i-1;
if ( ((i+j) % (width*2) )<width)
strip.setPixelColor(L,0,0,255);
else
strip.setPixelColor(L,255,0,0);
};
strip.show();
delay(wait);
}
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1;
for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
}
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}