Changing brightness on same strip. I want to take a strip of 45 leds.

Changing brightness on same strip.

I want to take a strip of 45 leds. I would like to make 0-15 white at max brightness level. 16-31 white at 10% of max brightness, and 32-44 white at max brightness again.
I am not sure if any of the math functions will help me with this, the best way I found is to set the rgb colors myself for each led.

CRGB::255,255,255 set leds 0-15
CRGB::050,050,050 set leds 16-31
CRGB::255,255,255 set leds 32-44

I tried to get the .fadeLightBy and .nscale8_video functions to work, but have failed so far. Anyone had success with this on fading only certain leds on the same strip?

Thanks!

Fading LED’s 4 through 6 (as I vaguely recall). LED 4 is 4*3 bytes per LED from the origin, and there’s 3 LED’s to fade:

fadeToBlackBy(leds+43, 3, fadeval); // 8 bit, 1 = slow, 255 = fast
nscale8(leds+4
3, 3,fadeval); // 8 bit, 1 = fast, 255 = slow

Disclaimer: Can’t recall if the ‘*3’ is required.

Thank you, I will try to work this in :slight_smile:

There are several ways you could do this such as:

a) Use three “for” loops, with the first and third loop setting
leds[i] = CRGB(255,255,255)
or leds[i] = CHSV(0,0,255)
or leds[i] = CRGB::White
and the middle for loop using
CRGB(25,25,25) or CHSV(0,0,25).

b) Three fills, one for each section:
fill_solid(leds, 16, CRGB::White);
fill_solid(leds+16, 16, CHSV(0,0,25); //start at pixel 16
fill_solid(leds+32, 13, CRGB::White); //start at pixel 32

c) Set all the leds full white and then fade the middle section back down before displaying the pixels.

//start at pixel 16, fade by 90% (230/256)
fadeToBlackBy( leds+16, 16, 230);

or if using a for loop:
leds[i].fadeToBlackBy(230); //fade by 90%

Thank you Marc. That works like a champ!
I got to looking at the memmove8 function and was wondering if I could use that to move the pixel data and then apply the fadeToBlackBy function!

I got this working perfectly:

fill_solid(leds, 7, CRGB::White);
memmove8(&leds[7],&leds[0], 7*sizeof(CRGB));
fadeToBlackBy(leds+7,7,230);
FastLED.show();

This way no matter what I display on the part I want copied, it will mimic it perfectly to the second section, just much dimmer!

(I would like the section towards the person’s eye not to cause blindness!)

Thank you both, wonderful advice!

I am testing, using the the excellent clyon, and got everything working great… but! I have tried to fade the second CRGB (bleds) after I use memmove8 to copy the first 14 leds from the CRBG (leds) strip. It works great, but when I try to then apply fadeToBlackBy function on the bleds, it throws no errors, just doesn’t seem to work. Any ideas?

Two different tries:

First one.

void loop() {
int dot2 = 216;
static uint8_t hue = 0;
Serial.print(“x”);
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS/2; i++) {
// Set the i’th led to red
leds[i] = CHSV(hue++, 255, 255);
leds[dot2] = CHSV(hue++, 255, 255);
memmove8(&bleds[0],&leds[0], 14*sizeof(CRGB));
if (i < 14){
bleds[i].fadeToBlackBy(240);

}

   // Show the leds
FastLED.show(); 
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
//delay(10);
memmove8(&bleds[0],&leds[0], 14*sizeof(CRGB));
FastLED.delay(1); 
dot2 = dot2 -1;

}

Second one.

void loop() {
int dot2 = 216;
static uint8_t hue = 0;
Serial.print(“x”);
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS/2; i++) {
// Set the i’th led to red
leds[i] = CHSV(hue++, 255, 255);
leds[dot2] = CHSV(hue++, 255, 255);
memmove8(&bleds[0],&leds[0], 14*sizeof(CRGB));
fadeToBlackBy(bleds+0,14,240);

   // Show the leds
FastLED.show(); 
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
//delay(10);
memmove8(&bleds[0],&leds[0], 14*sizeof(CRGB));
FastLED.delay(1); 
dot2 = dot2 -1;

}

Hello @Tim_Hay Please put your code on http://gist.github.com and share the link. Much easier to read on all devices, code won’t get mangled by G+, and line numbers can be referenced.

Sure thing Marc, thanks for the advice! (newbie learning!)

1st idea:
I tried to use the [i] to just map to the led number in the second set (bleds) and dim each one in as long as it wasn’t over the 14 in the set.

2nd idea:
I just tried to memmove and just use the fadetoblackby to the whole strip.

This should work. (Is it working for you?)
bleds[i].fadeToBlackBy(240);

I’m not sure if this works.
fadeToBlackBy(bleds+0,14,240);
I’ve never tried that formatting before, of only trying to operate on a certain block of pixels. Is that giving you an error?
(I’m traveling, can’t test any code right now.)

Neither throw errors (unless I try to use the bleds[i] in the first loop without putting it it’s own loop to not go past [13], which will hang it all).
They just don’t seem to actually get applied.
The fadetoBlackBy(bleds) works perfect after a memmove8 that isn’t in an IF loop.
I’ll keep banging away at it! :slight_smile:

@marmil I ended up using the FastLED controller call to show the strips, which works perfect for me since each strip is on it’s own output pin. This wouldn’t work well if you wanted a section only of a strip, and the fadetoBlackBy works perfect for that in most situations! For this I just removed all the fadetoBlackBy, etc and called it like this:

leds[dot2] = CHSV(hue++, 255, 255);
memmove8(&bleds[0],&leds[0], 14*sizeof(CRGB));
FastLED[0].showLeds(255);
FastLED[1].showLeds(10);

Works like a champ for anyone who runs into this problem!