// NeoPixel test program showing use of the WHITE channel for RGBW // pixels only (won't look correct on regular RGB NeoPixel strips). #include // Which pin on the Arduino is connected to the NeoPixels? // On a Trinket or Gemma we suggest changing this to 1: #define LED_PIN 4 // How many NeoPixels are attached to the Arduino? #define LED_COUNT 156 // 77 y 78 quedan en la punta // NeoPixel brightness, 0 (min) to 255 (max) #define BRIGHTNESS 50 // Declare our NeoPixel strip object: Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP strip.setBrightness(BRIGHTNESS); // Set BRIGHTNESS to about 1/5 (max = 255) } void loop() { // 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) //Fire(55,120,15); //Fire(100,120,15); } // 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(255, 255, 255, 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(strip.gamma8(j), strip.gamma8(j), strip.gamma8(j), strip.gamma8(j))); strip.show(); delay(wait); } for(int j=255; j>=0; j--) { // Ramp down from 255 to 0 strip.fill(strip.Color(strip.gamma8(j), strip.gamma8(j), strip.gamma8(j), 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(strip.gamma8(j), strip.gamma8(j), strip.gamma8(j), strip.gamma8(j))); strip.show(); } } delay(500); // Pause 1/2 second } void Fire(int Cooling, int Sparking, int SpeedDelay) { static byte heat[LED_COUNT]; int cooldown; // Step 1. Cool down every cell a little for ( int i = 0; i < LED_COUNT ; i++) { cooldown = random(0, ((Cooling * 10) / LED_COUNT) + 2); if (cooldown > heat[i]) { heat[i] = 0; } else { heat[i] = heat[i] - cooldown; } } // Step 2. Heat from each cell drifts 'up' and diffuses a little for ( int k = LED_COUNT - 1; k >= 2; k--) { heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3; } // Step 3. Randomly ignite new 'sparks' near the bottom if ( random(255) < Sparking ) { int y = random(7); heat[y] = heat[y] + random(160, 255); //heat[y] = random(160,255); } // Step 4. Convert heat to LED colors for ( int j = 0; j < LED_COUNT; j++) { setPixelHeatColor(j, heat[j] ); } strip.show(); delay(SpeedDelay); } void setPixelHeatColor (int Pixel, byte temperature) { // Scale 'heat' down from 0-255 to 0-191 byte t192 = round((temperature / 255.0) * 191); // calculate ramp up from byte heatramp = t192 & 0x3F; // 0..63 heatramp <<= 2; // scale up to 0..252 // figure out which third of the spectrum we're in: if ( t192 > 0x80) { // hottest setPixel(Pixel, 255, 255, heatramp, 0); } else if ( t192 > 0x40 ) { // middle setPixel(Pixel, 255, heatramp, 0, 0); } else { // coolest setPixel(Pixel, heatramp, 0, 0, 0); } } void setPixel(int Pixel, byte red, byte green, byte blue, byte white) { strip.setPixelColor(Pixel, strip.Color(red, green, blue, white)); }