1 #include <Adafruit_NeoPixel.h>
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);
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.
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);
28 // End of trinket special code
32 strip.show(); // Initialize all pixels to 'off'
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
52 //theaterChaseRainbow(50);
55 void rSlider(uint8_t wait) {
56 int pos = 0, dir = 1; //position and direction of eye
58 for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
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
67 for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
72 } else if(pos >= strip.numPixels()) {
73 pos = strip.numPixels() - 2;
79 void wSlider(uint8_t wait) {
80 int pos = 0, dir = 1; //position and direction of eye
82 for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
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
91 for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
96 } else if(pos >= strip.numPixels()) {
97 pos = strip.numPixels() - 2;
103 void bSlider(uint8_t wait) {
104 int pos = 0, dir = 1; //position and direction of eye
106 for(uint16_t i=0; i<(strip.numPixels()*4); i++) {
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
115 for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
120 } else if(pos >= strip.numPixels()) {
121 pos = strip.numPixels() - 2;
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);
134 for(uint16_t i=0; i<strip.numPixels(); i++) {
135 strip.setPixelColor(i, blue);
139 for(int r=0; r<400; r++) {
140 pixel = random(0,139);
141 //int rColor = random(0,100);
143 strip.setPixelColor(pixel,white);
145 // strip.setPixelColor(pixel,red);
149 strip.setPixelColor(pixel,blue);
152 for(uint16_t i=0; i<strip.numPixels(); i++) {
153 strip.setPixelColor(i, off);
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);
169 void rainbow(uint8_t wait) {
172 for(j=0; j<256; j++) {
173 for(i=0; i<strip.numPixels(); i++) {
174 strip.setPixelColor(i, Wheel((i+j) & 255));
181 // Slightly different, this makes the rainbow equally distributed throughout
182 void rainbowCycle(uint8_t wait) {
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));
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
205 for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
206 strip.setPixelColor(i+q, 0); //turn every third pixel off
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
223 for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
224 strip.setPixelColor(i+q, 0); //turn every third pixel off
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;
235 return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
239 return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
242 return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);