#include #ifdef __AVR__ #include #endif #define PIN 5 #define NUMPIXELS 64 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first. void setup() { // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code strip.begin(); strip.setBrightness(50); strip.show(); // Initialize all pixels to 'off' } void loop() { //explode(10); //return; // delay(1000); goleft(15); //return; delay(100); // Some example procedures showing how to display to the pixels: colorWipe(strip.Color(255, 0, 0), 50); // Red colorWipe(strip.Color(0, 255, 0), 50); // Green colorWipe(strip.Color(0, 0, 255), 50); // Blue //colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW // Send a theater pixel chase in... theaterChase(strip.Color(127, 127, 127), 50); // White theaterChase(strip.Color(127, 0, 0), 50); // Red theaterChase(strip.Color(0, 0, 127), 50); // Blue rainbow(20); rainbowCycle(20); theaterChaseRainbow(50); // Fill along the length of the strip in various colors... colorWipe(strip.Color(255, 0, 0) , 50); // Red colorWipe(strip.Color( 0, 255, 0) , 50); // Green colorWipe(strip.Color( 0, 0, 255) , 50); // Blue colorWipe(strip.Color( 0, 0, 0, 255), 50); // True white (not RGB white) whiteOverRainbow(75, 5); pulseWhite(5); rainbowFade2White(3, 3, 1); } // Fill strip pixels one after another with a color. Strip is NOT cleared // first; anything there will be covered pixel by pixel. Pass in color // (as a single 'packed' 32-bit value, which you can get by calling // strip.Color(red, green, blue) as shown in the loop() function above), // and a delay time (in milliseconds) between pixels. void colorWipe(uint32_t color, int wait) { for(int i=0; i= strip.numPixels()) whiteLength = strip.numPixels() - 1; int head = whiteLength - 1; int tail = 0; int loops = 3; int loopNum = 0; uint32_t lastTime = millis(); uint32_t firstPixelHue = 0; for(;;) { // Repeat forever (or until a 'break' or 'return') for(int i=0; i= tail) && (i <= head)) || // If between head & tail... ((tail > head) && ((i >= tail) || (i <= head)))) { strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white } else { // else set rainbow int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); } } strip.show(); // Update strip with new contents // There's no delay here, it just runs full-tilt until the timer and // counter combination below runs out. firstPixelHue += 40; // Advance just a little along the color wheel if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail? if(++head >= strip.numPixels()) { // Advance head, wrap around head = 0; if(++loopNum >= loops) return; } if(++tail >= strip.numPixels()) { // Advance tail, wrap around tail = 0; } lastTime = millis(); // Save time of last movement } } } void pulseWhite(uint8_t wait) { for(int j=0; j<256; j++) { // Ramp up from 0 to 255 // Fill entire strip with white at gamma-corrected brightness level 'j': strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); strip.show(); delay(wait); } for(int j=255; j>=0; j--) { // Ramp down from 255 to 0 strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); strip.show(); delay(wait); } } void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) { int fadeVal=0, fadeMax=100; // Hue of first pixel runs 'rainbowLoops' complete loops through the color // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so // just count from 0 to rainbowLoops*65536, using steps of 256 so we // advance around the wheel at a decent clip. for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536; firstPixelHue += 256) { for(int i=0; i= ((rainbowLoops-1) * 65536)) { // Last loop, if(fadeVal > 0) fadeVal--; // fade out } else { fadeVal = fadeMax; // Interim loop, make sure fade is at max } } for(int k=0; k=0; j--) { // Ramp down 255 to 0 strip.fill(strip.Color(0, 0, 0, strip.gamma8(j))); strip.show(); } } delay(500); // Pause 1/2 second } void goleft(uint8_t wait){ for(int i=NUMPIXELS;i>0;i--){ //LEFT // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 strip.setPixelColor(i, strip.Color(0,255,0)); // bright green color. strip.show(); // This sends the updated pixel color to the hardware. delay(wait); // Delay for a period of time (in milliseconds). // strip.clear(); }} void explode(uint8_t wait){ for(int i=NUMPIXELS;i>0;i--){ //Exploded star // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 for(int ii=6;ii>0;ii--){ strip.setPixelColor(ii, strip.Color(0,255,0)); // bright green color. strip.setPixelColor(ii, strip.Color(0,255,0)); // bright green color. } strip.show(); // This sends the updated pixel color to the hardware. delay(wait); // Delay for a period of time (in milliseconds). // strip.clear(); }}