initial commit
[4thJuly.git] / _4thJuly / _4thJuly.ino
1 #include <Adafruit_NeoPixel.h>
2 #ifdef __AVR__
3   #include <avr/power.h>
4 #endif
5
6 #define PIN 6
7
8 // Parameter 1 = number of pixels in strip
9 // Parameter 2 = Arduino pin number (most are valid)
10 // Parameter 3 = pixel type flags, add together as needed:
11 //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
12 //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
13 //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
14 //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
15 //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
16 Adafruit_NeoPixel strip = Adafruit_NeoPixel(139, PIN, NEO_GRB + NEO_KHZ800);
17
18 // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
19 // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
20 // and minimize distance between Arduino and first pixel.  Avoid connecting
21 // on a live circuit...if you must, connect GND first.
22
23 void setup() {
24   // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
25   #if defined (__AVR_ATtiny85__)
26     if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
27   #endif
28   // End of trinket special code
29
30
31   strip.begin();
32   strip.show(); // Initialize all pixels to 'off'
33 }
34
35 void loop() {
36   blueSparkle(50);
37   rSlider(50); //red
38   wSlider(50); //white
39   bSlider(50); //blue
40   // Some example procedures showing how to display to the pixels:
41   colorWipe(strip.Color(255, 0, 0), 30); // Red
42   colorWipe(strip.Color(127, 127, 127), 30); // White
43   colorWipe(strip.Color(0, 0, 255), 30); // Blue
44 //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
45   // Send a theater pixel chase in...
46   theaterChase(strip.Color(127, 0, 0), 50); // Red
47   theaterChase(strip.Color(127, 127, 127), 50); // White
48   theaterChase(strip.Color(0, 0, 127), 50); // Blue
49
50   //rainbow(20);
51   //rainbowCycle(20);
52   //theaterChaseRainbow(50);
53 }
54
55 void rSlider(uint8_t wait) {
56   int pos = 0, dir = 1; //position and direction of eye
57
58   for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
59     int j;
60     strip.setPixelColor(pos - 2, 0x100000); // Dark red
61     strip.setPixelColor(pos - 1, 0x800000); // Medium red
62     strip.setPixelColor(pos    , 0xFF3000); // Center pixel is brightest
63     strip.setPixelColor(pos + 1, 0x800000); // Medium red
64     strip.setPixelColor(pos + 2, 0x100000); // Dark red
65     strip.show();
66     delay(10);
67     for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
68     pos += dir;
69     if(pos < 0) {
70       pos = 1;
71       dir = -dir;
72     } else if(pos >= strip.numPixels()) {
73       pos = strip.numPixels() - 2;
74       dir = -dir;
75     }
76   }
77 }
78
79 void wSlider(uint8_t wait) {
80   int pos = 0, dir = 1; //position and direction of eye
81
82   for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
83     int j;
84     strip.setPixelColor(pos - 2, 0x101010); // Dark red
85     strip.setPixelColor(pos - 1, 0x7F7F7F); // Medium red
86     strip.setPixelColor(pos    , 0xFFFFFF); // Center pixel is brightest
87     strip.setPixelColor(pos + 1, 0x7F7F7F); // Medium red
88     strip.setPixelColor(pos + 2, 0x101010); // Dark red
89     strip.show();
90     delay(10);
91     for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
92     pos += dir;
93     if(pos < 0) {
94       pos = 1;
95       dir = -dir;
96     } else if(pos >= strip.numPixels()) {
97       pos = strip.numPixels() - 2;
98       dir = -dir;
99     }
100   }
101 }
102
103 void bSlider(uint8_t wait) {
104   int pos = 0, dir = 1; //position and direction of eye
105
106   for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
107     int j;
108     strip.setPixelColor(pos - 2, 0x000010); // Dark red
109     strip.setPixelColor(pos - 1, 0x000080); // Medium red
110     strip.setPixelColor(pos    , 0x0030FF); // Center pixel is brightest
111     strip.setPixelColor(pos + 1, 0x000080); // Medium red
112     strip.setPixelColor(pos + 2, 0x000010); // Dark red
113     strip.show();
114     delay(10);
115     for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
116     pos += dir;
117     if(pos < 0) {
118       pos = 1;
119       dir = -dir;
120     } else if(pos >= strip.numPixels()) {
121       pos = strip.numPixels() - 2;
122       dir = -dir;
123     }
124   }
125 }
126
127
128 void blueSparkle(uint8_t wait) {
129   uint32_t blue = strip.Color(0, 0, 255);
130   uint32_t red = strip.Color(255, 0, 0);
131   uint32_t white = strip.Color(255, 255, 255);
132   uint32_t off = strip.Color(0, 0, 0);
133
134   for(uint16_t i=0; i<strip.numPixels(); i++) {
135     strip.setPixelColor(i, blue);
136   }
137   strip.show();
138   int pixel=0;
139   for(int r=0; r<400; r++) {
140     pixel = random(0,139);
141     //int rColor = random(0,100);
142     //if (rColor > 50) {
143       strip.setPixelColor(pixel,white);
144     //} else {
145     //  strip.setPixelColor(pixel,red);
146     //}
147     strip.show();
148     delay(50);
149     strip.setPixelColor(pixel,blue);
150     strip.show();
151   }
152   for(uint16_t i=0; i<strip.numPixels(); i++) {
153     strip.setPixelColor(i, off);
154   }
155   strip.show();
156
157   delay(wait);
158 }
159
160 // Fill the dots one after the other with a color
161 void colorWipe(uint32_t c, uint8_t wait) {
162   for(uint16_t i=0; i<strip.numPixels(); i++) {
163     strip.setPixelColor(i, c);
164     strip.show();
165     delay(wait);
166   }
167 }
168
169 void rainbow(uint8_t wait) {
170   uint16_t i, j;
171
172   for(j=0; j<256; j++) {
173     for(i=0; i<strip.numPixels(); i++) {
174       strip.setPixelColor(i, Wheel((i+j) & 255));
175     }
176     strip.show();
177     delay(wait);
178   }
179 }
180
181 // Slightly different, this makes the rainbow equally distributed throughout
182 void rainbowCycle(uint8_t wait) {
183   uint16_t i, j;
184
185   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
186     for(i=0; i< strip.numPixels(); i++) {
187       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
188     }
189     strip.show();
190     delay(wait);
191   }
192 }
193
194 //Theatre-style crawling lights.
195 void theaterChase(uint32_t c, uint8_t wait) {
196   for (int j=0; j<10; j++) {  //do 10 cycles of chasing
197     for (int q=0; q < 3; q++) {
198       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
199         strip.setPixelColor(i+q, c);    //turn every third pixel on
200       }
201       strip.show();
202
203       delay(wait);
204
205       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
206         strip.setPixelColor(i+q, 0);        //turn every third pixel off
207       }
208     }
209   }
210 }
211
212 //Theatre-style crawling lights with rainbow effect
213 void theaterChaseRainbow(uint8_t wait) {
214   for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
215     for (int q=0; q < 3; q++) {
216       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
217         strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
218       }
219       strip.show();
220
221       delay(wait);
222
223       for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
224         strip.setPixelColor(i+q, 0);        //turn every third pixel off
225       }
226     }
227   }
228 }
229
230 // Input a value 0 to 255 to get a color value.
231 // The colours are a transition r - g - b - back to r.
232 uint32_t Wheel(byte WheelPos) {
233   WheelPos = 255 - WheelPos;
234   if(WheelPos < 85) {
235     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
236   }
237   if(WheelPos < 170) {
238     WheelPos -= 85;
239     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
240   }
241   WheelPos -= 170;
242   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
243 }