Skip to content

Instantly share code, notes, and snippets.

@kriegsman
Created June 30, 2014 17:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kriegsman/ccffc81a74bc03636ce1 to your computer and use it in GitHub Desktop.
Save kriegsman/ccffc81a74bc03636ce1 to your computer and use it in GitHub Desktop.
Red, White, and Blue stripes with "glitter" flashes sketch (for FastLED v2.1 or later)
#include<FastLED.h>
// Red, White, and Blue stripes with "glitter" flashes
// Mark Kriegsman, June 30, 2014
// requires FastLED v2.1 or later
#define NUM_LEDS 30
#define LED_PIN 5
#define COLOR_ORDER GRB
#define BRIGHTNESS 64
CRGB leds[NUM_LEDS];
uint8_t data[ NUM_LEDS];
void setup() {
delay(3000);
FastLED.addLeds<WS2811,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
fill_data_array();
render_data_with_palette();
add_glitter();
FastLED.show();
FastLED.delay(20);
}
void fill_data_array()
{
static uint8_t startValue = 0;
startValue = startValue + 2;
uint8_t value = startValue;
for( int i = 0; i < NUM_LEDS; i++) {
data[i] = triwave8( value); // convert value to an up-and-down wave
value += 7;
}
}
CRGBPalette16 gPalette (
CRGB::Black, CRGB::Black,
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray,
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
CRGB::Black, CRGB::Black
);
void render_data_with_palette()
{
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( gPalette, data[i], 128, BLEND);
}
}
void add_glitter()
{
int chance_of_glitter = 5; // percent of the time that we add glitter
int number_of_glitters = 3; // number of glitter sparkles to add
int r = random8(100);
if( r < chance_of_glitter ) {
for( int j = 0; j < number_of_glitters; j++) {
int pos = random16( NUM_LEDS);
leds[pos] = CRGB::White; // very bright glitter
}
}
}
@TRYING-HARD
Copy link

I'm New to Arduino programming and trying out different effects, your examples are all really good and fairly easy to follow, however with this sketch when trying to compile this code i get the message

'BLEND' was not declared in this scope.

Can you help with the missing line? I'm guessing it will look something like this CRGB pixelColor = blend( startColor, endColor, amountOfBlending but i dont really get the syntax yet.

@TRYING-HARD
Copy link

Dont worry i got it. This is from an older version of Fastled so rename BLEND to LINEARBLEND and it all works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment