Can anyone give me a run-down of the blur1d function,

Can anyone give me a run-down of the blur1d function, how it works and parameters? I’m testing it out, adding random blocks of colour onto my 150 led strip using fill_solid, then running

blur1d(leds, NUM_LEDS, 60);

…in a loop. It is causing the blocks of colour to fade away in the manner of fadetoblackby, and the blocks - sort of - fade out at the edges first.

Can I specify a particular range or blocks of leds instead of NUM_LEDS?

If I’m applying it to NUM_LEDS (all my leds) how does it know to fade out (for example) the edges of just a fill_solid block of 30 leds lit up in the middle of the strip?

Also what is the last parameter for and what is its range?

Thanks, you’re all wonderful people :slight_smile:

I though blur1d’s function was to fade out a block of lit leds towards the edges, which it is doing, but it also produces a shimmering flickering effect as blur1d is repeatedly run and the lit leds fade. Is that what it’s supposed to do?

Oh. It’s not doing the shimmery flickering thing now. Sometimes the Arduino seems to need a reboot.

This is really working for me now - happy :slight_smile: But still don’t know what that value in blur1d actually does…

#include <FastLED.h>
#define NUM_LEDS 150
#define DATA_PIN 13

CRGBArray<NUM_LEDS> leds;
byte hue;

void setup() {
// put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
int pos = random16(10, NUM_LEDS - 10); // = a random number between 16 - 134. Keeps raindrop away from edge, otherwise sometimes sum = random number!
int prand = random(2, 6); // the distance a single block of colour will extend either side of the central seed value “pos”
int left_pos = pos - prand; // extends the colour block ‘prand’ leds to the left
int right_pos = pos + prand; // extends the colour block ‘prand’ leds to the right
int ledcol = random(0, 255); //100-165 sets the leds to HSV greens and blues

leds(left_pos,right_pos) = CHSV(ledcol,255,255);

FastLED.show();

for (int i = 0; i < 20; i++) {   //  alter the i < x value to speed up or slow down the action
  fadeToBlackBy(leds, NUM_LEDS, 1);   // fade all leds by a small amount every loop
  blur1d(leds, NUM_LEDS, 150);  // "blurs" the blocks of colour = fading it out to left and right. Not sure what the value at the end does yet. 
  FastLED.show();
  //delay(30);  // enable and change value to slow things down
}

}

The value at the end is blend amount, and the fade is intended. From the source code:
0 = no spread at all
64 = moderate spreading
172 = maximum smooth, even spreading

173…255 = wider spreading, but increasing flicker

Total light is NOT entirely conserved, so many repeated calls to ‘blur’ will also result in the light fading, eventually all the way to black; this is by design so that it can be used to (slowly) clear the LEDs to black.

Thanks Techy! But where is the source code. I spent some time googling for info and couldn’t find any.

Does blur1d always act upon the entire led strip, or can you target it to a specific block of leds e.g. something like:

blur1d(leds, 75, 150, 255);

?

Aha I see - blur1d is blurring lit leds, smearing them to either side beyond the area I’ve actually told to light. So e.g. if you code “light up 5 leds in the middle of the strip red then do blur1d” what you get is maybe 15 leds lit up: the 5 original ones brightly and 4 or 5 either side tailing off in increasing dimness. The amount of smearing is dependent on that last value.
Cool :slight_smile:

Each call to blur only smears each led to the two leds each side regardless of the blend amount, that value instead represents how much of the color is blended to those neighbors. To get 5 each side you’d want to call it five times (or see the same effect after 5 loops/frames).

The leds in the middle would also gradually dim, think of it as also smearing the black inwards. So in that example you’d probably want to set the middle 5 leds to the original color before each blur. Finally the whole thing would eventually fade towards black if you didn’t do that, so it would all end up quite dim.

The latest source code is over at GitHub ( https://github.com/FastLED/FastLED )and is well commented, and there’s some slightly outdated documentation at http://fastled.io/docs/3.1/index.html

Yes I’m blurring in a loop that runs 20 times, so am seeing more smearing than just the two adjacent leds, plus the whole thing is fading to black very nicely. Also getting a cool flickering/shimmering effect when the blur1d value is high but I slow the loop with a short delay or 20-30 milliseconds - not sure why that’s happening though…

I’m probably being dumb but I can’t see any reference to blur1d at those links. Could you possibly supply screenshots or details as to exactly where they are?

Sorry, it’s in colorutils.cpp on GitHub, and the documentation has it at Modules->Color utility functions.

Brilliant, got it. Thanks.
This is working great. I’m lighting 9 leds at a time in random colours and random places, then blurring in a loop that also has a delay command in it. By tweaking the number of blurs (currently 16) and the delay time (currently 100) you can get a really cool balance, so the strip isn’t ever fully lit but is dynamically busy, and the interfacing and blurring between the different blocks of colour as they age and overlap and fade is fascinating to watch - lots of flickering and shimmering and all sorts :smiley:

For anyone interesting in my amateur efforts here’s the script.

#include <FastLED.h>
#define NUM_LEDS 150
#define DATA_PIN 13

CRGBArray<NUM_LEDS> leds;
byte hue;

void setup() {
// put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
int pos = random16(10, NUM_LEDS - 10); // = a random number between 16 - 134. Keeps ‘raindrops’ away from edge
int prand = 4; // the distance a single block of colour will extend either side of the central seed value “pos”
int left_pos = pos - prand; // extends the colour block ‘prand’ leds to the left
int right_pos = pos + prand; // extends the colour block ‘prand’ leds to the right
int ledcol = random(0, 255); //any colour

leds(left_pos,right_pos) = CHSV(ledcol,255,255);


FastLED.show();

for (int i = 0; i < 16; i++) {   //  alter the i < x value to speed up or slow down the action
  // get above <x no. set right along with the delay value and it balances between filling the strip and fading it, constantly in motion blending and blurring. 
  // <16 with 100 delay at the end works! 
  blur1d(leds, NUM_LEDS, 255);  
  /* "blurs" the blocks of colour = fading it out to left and right.  
      0 = no spread at all
      64 = moderate spreading
      172 = maximum smooth, even spreading
      173..255 = wider spreading, but increasing flicker
      NOTE: it spreads the lit block wider, smearing it into nearby unl
   */
  FastLED.show();
  delay(100);  // enable and change value to slow things down
}

}