LED partial array for glitter

I have a strip of 146 LEDs. WS2815. I want to light 75 of them in sequence and then get the remaining 72 to light using "glitter" from fastLED for 3 seconds and then write to those 72 to become solid colors. I can get the whole strip to glitter but I can't get just the LEDs from #74 to #145 to glitter. It seems that I'm having a problem defining my starting point in the array. I don't want to start at 0 but rather at 75 any help would be more than welcome. Just a note to please be gentle with me as I am 76 years old and this is for a project for Burning Man. Not that that really makes any difference. Thanks.

#include "FastLED.h"

#define LEDPIN     7
#define LED_TYPE     WS2815
#define NUM_LEDS    146
#define BRIGHTNESS 60
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];


void setup() {
//sanity delay
delay(1000); 

// set up LED strip info
FastLED.addLeds<LED_TYPE,LEDPIN>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}


void loop() {
fadeToBlackBy( leds, NUM_LEDS, 20);
/*  It takes 3 parameters: 
1  the array you are dimming, 
2  the number of LEDs in that array you are dimming starting from index [0] (the first LED in the array), 
3  and the amount you would like to fade them. Changing the third variable changes how quickly the lights fadeSo an example would be:
This would reduce the colour values for all the LEDs to 20/256ths of their current value 
in a previous line we set the whole array of LEDs to CRGB:: white, which means that the r, g, and b values are all 255. 
Then we would write the line:
*/
fadeToBlackBy(arrayName, lengthOfStrip, 10); 

//changing this variable will increase the chance of a "star" popping up
addGlitter(200);

FastLED.show();
}


//glitter effect
void addGlitter( fract8 chanceOfGlitter) {
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;}
}

random16(NUM_LEDS) will give you a random number in the [0, NUM_LEDS[ interval

you want only the last 72 to glitter, so generate a random number for that range and add 75 to that number to impact only the tail

try

leds[75 +  random16(71) ] += CRGB::White;

Thank you, thank you, thank you. That was exactly what I was looking for. I had a gut feeling that I needed to do something like what you suggested but I just didn't know where of how to do it. You are a lifesaver.

cool - have fun ! (share pictures of the finished project !)

You could take advantage of the CPixelView class provided by FastLED. This provides a "view" into a subsection of an existing LED array and automatically adjusts to provide zero-based indexing for the subsection. So, you'd add below the definition of the LED array:

CRGB leds[NUM_LEDS];
const size_t glitterStart = 75;
const size_t numGlitterLeds = NUM_LEDS - glitterStart;
CPixelView<CRGB> glitterLeds(leds, glitterStart, glitterStart + numGlitterLeds - 1);

and your addGlitter function would be come:

//glitter effect
void addGlitter(fract8 chanceOfGlitter) {
	if (random8() < chanceOfGlitter) {
		glitterLeds[random16(numGlitterLeds)] += CRGB::White;
	}
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.