FastLED Pulse of Color and then Fade

FastLED Pulse of Color and then Fade

The following was done on a 12x12 grid / matrix of WS1812B LEDs (made from a strip).  I got the code from Scott Kletzien in the FastLED Google+ community. I had to tweak it a little bit to get it to work with my LEDs, and I stumbled with the setRGB function -- I thought it was used the same as HSV settings, but I was wrong.  I have an explanation of how it works HERE.  It's also briefly explained in the code below.




/*
Put together & tested by:
Scottie Digital
 */
#include "FastLED.h"
#define NUM_LEDS 144  // # of LEDS in the strip
CRGB leds[NUM_LEDS];
#define DATA_PIN 6 // Output Pin to Data Line on Strip

int fadeAmount = 5;  // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
int brightness = 0;

void setup()
{
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop()
{
   for(int i = 0; i < NUM_LEDS; i++ )
   {
   leds[i].setRGB(0,255,0);  // setRGB functions works by setting
                             // (RED value 0-255, GREEN value 0-255, BLUE value 0-255)
                             // RED = setRGB(255,0,0)
                             // GREEN = setRGB(0,255,0)
   leds[i].fadeLightBy(brightness);
  }
  FastLED.show();
  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade:
  if(brightness == 0 || brightness == 255)
  {
    fadeAmount = -fadeAmount ;
  }  
  delay(20);  // This delay sets speed of the fade. I usually do from 5-75 but you can always go higher.
}




No comments:

Post a Comment