LED Setup
Number of LEDs
Fade delay
Slow
Fast
Faster
Tail speed
Slow
Fast
Faster
LEDs color
Red
Yellow
Green
Teal
Blue
Purple
LEDs brightness
High
Medium
Low
#include "FastLED.h" FASTLED_USING_NAMESPACE // FastLED "100-lines-of-code" demo reel, showing just a few // of the kinds of animation patterns you can quickly and easily // compose using FastLED. // // This example also shows one easy way to define multiple // animations patterns and have them automatically rotate. // // -Mark Kriegsman, December 2014 #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif #define DATA_PIN 6 #define DATA_PIN2 5 #define LED_TYPE WS2812B #define COLOR_ORDER GRB //***EDIT CODE AREA
// NUM_LEDS - how many LEDs are in your strip?
#define NUM_LEDS 20
// TRAIL_FADE - Range is 0-255 0 won't fade, 20 fades quickly, 255 instant off.
#define TRAIL_FADE 5
// TRAIL_SPEED - how quickly the trail moves, range is 0-255. 0-really slow, 50-quick, 255 is light speed
#define TRAIL_SPEED 20
// Uses HSVC color wheel, 0-red, 48-yellow, 80-green, 128-teal, 170-blue, 210-purple and 255 is back to red
#define TRAIL_COLOR 0
// BRIGHTNESS - 255 is full bright, 0 is off
#define BRIGHTNESS 255
//****END EDIT CODE AREA #define FRAMES_PER_SECOND 120 CRGB leds[NUM_LEDS]; void setup() { delay(3000); // 3 second delay for recovery // tell FastLED about the LED strip configuration FastLED.addLeds
(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); FastLED.addLeds (leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // set master brightness control FastLED.setBrightness(BRIGHTNESS); } // List of patterns to cycle through. Each is defined as a separate function below. typedef void (*SimplePatternList[])(); SimplePatternList gPatterns = { sinelon_mod }; uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current uint8_t gHue = 0; // rotating "base color" used by many of the patterns void loop() { // Call the current pattern function once, updating the 'leds' array gPatterns[gCurrentPatternNumber](); // send the 'leds' array out to the actual LED strip FastLED.show(); // insert a delay to keep the framerate modest FastLED.delay(1000/FRAMES_PER_SECOND); // do some periodic updates EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically } #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) void nextPattern() { // add one to the current pattern number, and wrap around at the end gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); } void sinelon_mod() { // a colored dot sweeping back and forth, with fading trails fadeToBlackBy( leds, NUM_LEDS, TRAIL_FADE ); int pos = beatsin16( TRAIL_SPEED, 0, NUM_LEDS-1 ); leds[pos] += CHSV( TRAIL_COLOR, 255, 255); }