Skip to content

Instantly share code, notes, and snippets.

@kriegsman
Last active December 2, 2017 16:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriegsman/981cc6f501d30dfd82a7 to your computer and use it in GitHub Desktop.
Save kriegsman/981cc6f501d30dfd82a7 to your computer and use it in GitHub Desktop.
Example showing how to make a simple striped palette, and use it to animated blended color bars
#include <FastLED.h>
// Example showing how to make a simple striped color palette,
// and use it to animated blended color bars
#define LED_PIN 3
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
void setupStripedPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
{
// Sets up a palette with alternating stripes of
// colors "A" and "B" -- with color "AB" between
// where A fades into B, and color "BA" where B fades
// into A.
// The stripes of "A" are narrower than the stripes of "B",
// but an equal-width arrangement is also shown.
currentPalette = CRGBPalette16(
A, A, A, A, AB, B, B, B, B, B, B, B, B, B, B, BA
// A, A, A, A, A, A, A, AB, B, B, B, B, B, B, B, BA
);
}
void setup() {
delay( 3000 ); // power-up safety delay
FastLED.addLeds<WS2811,LED_PIN,GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// This example shows stripes with NO gaps between them; the colors
// cross-fade at the boundaries. An additional setup alternative is
// provided that puts a 'black' gap between the colors, so they don't
// bleed into each other if you prefer that.
// Color stripes with NO gaps between them -- colors will crossfade
setupStripedPalette( CRGB::Red, CRGB::Red, CRGB::Green, CRGB::Green);
// Color stripes WITH gaps of space (black) between them
//setupStripedPalette( CRGB::Red, CRGB::Black, CRGB::Green, CRGB::Black);
}
void loop()
{
static uint8_t startIndex = 0;
startIndex = startIndex + 2; /* higher = faster motion */
fill_palette( leds, NUM_LEDS,
startIndex, 8, /* higher = narrower stripes */
currentPalette, 255, LINEARBLEND);
FastLED.show();
FastLED.delay(1000 / 60);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment