forked from c4ss4ndr4/Smell-The-Flowers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmell_the_flowers_v1.ino
314 lines (245 loc) · 8.28 KB
/
smell_the_flowers_v1.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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include <SoftwareSerial.h>
#include "Adafruit_WS2801.h"
#include "SPI.h" // Comment out this line if using Trinket or Gemma
#ifdef __AVR_ATtiny85__
#include <avr/power.h>
#endif
/* Flowers Code similar to the Dress Code
modified by: Cassandra Marshall
Cassandra Marshall's version
Strand of WS2801 changes with the XBEE serial signals sent from the hat.
Poi serial messages change the lights on the strand to correspond to the lights on the poi.
If one of the poi changes color sequences it sends a signal to the hat which is a transmits a sequence change.
Keyboard strokes change the lights in the strand.
/*****************************************************************************
Example sketch for driving Adafruit WS2801 pixels!
Designed specifically to work with the Adafruit RGB Pixels!
12mm Bullet shape ----> https://www.adafruit.com/products/322
12mm Flat shape ----> https://www.adafruit.com/products/738
36mm Square shape ----> https://www.adafruit.com/products/683
These pixels use SPI to transmit the color data, and have built in
high speed PWM drivers for 24 bit color per pixel
2 pins are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
*****************************************************************************/
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
// The colors of the wires may be totally different so
// BE SURE TO CHECK YOUR PIXELS TO SEE WHICH WIRES TO USE!
uint8_t dataPin = 2; // Yellow wire on Adafruit Pixels
uint8_t clockPin = 3; // Green wire on Adafruit Pixels
// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply
// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);
// Optional: leave off pin numbers to use hardware SPI
// (pinout is then specific to each board and can't be changed)
//Adafruit_WS2801 strip = Adafruit_WS2801(25);
// For 36mm LED pixels: these pixels internally represent color in a
// different format. Either of the above constructors can accept an
// optional extra parameter: WS2801_RGB is 'conventional' RGB order
// WS2801_GRB is the GRB order required by the 36mm pixels. Other
// than this parameter, your code does not need to do anything different;
// the library will handle the format change. Examples:
//Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin, WS2801_GRB);
//Adafruit_WS2801 strip = Adafruit_WS2801(25, WS2801_GRB);
SoftwareSerial mySerial(10,11); // RX, TX
int sensorPin = 0; //analog pin 0
byte sensorVal; //sensor value variable
byte lilyVal;
//register global hue value
byte hue;
byte color;
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif
strip.begin();
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Serial.println("Goodnight moon!");
// Update LED contents, to start they are all 'off'
strip.show();
// set the data rate for the SoftwareSerial port
mySerial.begin(57600);
// mySerial.println("Hello, world?");
Serial.println("I'm here!");
/*Make NeoPixels white */
colorWipe(Color(127, 127, 127), 10); // White
rainbowCycle(1);
hue = 0;
// mySerial.write(computerByte);
}
void loop() {
//Read Proxmity
sensorVal = analogRead(sensorPin);
Serial.println(sensorVal); //print sensor reading
lightLED(sensorVal);
//convert the hue to a 24-bit color
/* uint32_t color = Wheel(hue);
//Go through each Pixel on the strip and set its color
for (int i=0; i<strip.numPixels(); i++)
{
//set pixel color
strip.setPixelColor(i, color);
strip.show(); // write all the pixels out
delay(10);
}*/
/* this is the for each for the rainbow cycle */
int i, j;
uint32_t color = Wheel( ((i * 256 / strip.numPixels()) + j) % 256) ;
for (j=0; j < 256 * 1; j++) { // 5 cycles of all 25 colors in the wheel
for (i=0; i < strip.numPixels(); i++) {
// tricky math! we use each pixel as a fraction of the full 96-color wheel
// (thats the i / strip.numPixels() part)
// Then add in j which makes the colors go around per pixel
// the % 96 is to make the wheel cycle around
strip.setPixelColor(i, (Wheel( (((i * 256 / strip.numPixels()) + j) % 256) % hue )+ hue));
}
strip.show(); // write all the pixels out
delay(5);
}
//rainbowCycle(10);
} //end loop
/* set hue depending on the value from the proximity sensor */
void lightLED(byte){
//Value from Sensor
if (sensorVal < 100 )
{
hue = 0;
Serial.println(hue);
}
else if (sensorVal < 150)
{
hue = 80; //Red
Serial.println(hue);
}
else if (sensorVal < 200)
{
hue = 30; //Green
Serial.println(hue);
}
else if (sensorVal < 250)
{
hue = 180; // Blue
Serial.println(hue);
}
else if (sensorVal < 300)
{
hue = 280;//Purple
Serial.println(hue);
}
else if (sensorVal < 400)
{
hue = 180;// Teal
Serial.println(hue);
}
else if (sensorVal < 500)
{
hue = 50; //Orange
Serial.println(hue);
}
else
{
hue = 0; // White
Serial.println(hue);
}
}
/*Sequence Functions*/
void whiteRainbow(){
colorWipe(Color(127, 127, 127), 1); // White
}
void redRainbow(){
colorWipe(Color(255, 0, 0), 1); // Red
}
void greenRainbow(){
colorWipe(Color(0, 255, 0), 1); // Green
}
void blueRainbow(){
colorWipe(Color(0, 0, 255), 1); // Blue
}
void purpleRainbow(){
colorWipe(Color(127, 0, 127), 1); // Purple
}
void tealRainbow(){
colorWipe(Color(0, 127, 127), 1);// Teal
}
void yellowRainbow(){
colorWipe(Color(127, 255, 0), 1); // Yellow
}
/*Color Pattern Functions*/
void rainbow(uint8_t wait) {
int i, j;
for (j=0; j < 256; j++) { // 3 cycles of all 256 colors in the wheel
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel( (i + j) % 255));
}
strip.show(); // write all the pixels out
delay(wait);
}
}
// Slightly different, this one makes the rainbow wheel equally distributed
// along the chain
void rainbowCycle(uint8_t wait) {
int i, j;
for (j=0; j < 256 * 1; j++) { // 5 cycles of all 25 colors in the wheel
for (i=0; i < strip.numPixels(); i++) {
// tricky math! we use each pixel as a fraction of the full 96-color wheel
// (thats the i / strip.numPixels() part)
// Then add in j which makes the colors go around per pixel
// the % 96 is to make the wheel cycle around
strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
}
strip.show(); // write all the pixels out
delay(wait);
}
}
// fill the dots one after the other with said color
// good for testing purposes
void colorWipe(uint32_t c, uint8_t wait) {
int i;
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
/* Helper functions */
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
if (WheelPos < 85) {
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
// Some example procedures showing how to display to the pixels
/*colorWipe(Color(255, 0, 0), 50);
colorWipe(Color(0, 255, 0), 50);
colorWipe(Color(0, 0, 255), 50);
rainbow(20);
rainbowCycle(20);*/