A short Question, how can I use the function Fadetoblackby(...) with hsv colors?

A short Question, how can I use the function Fadetoblackby(…) with hsv colors? In the library it isn’t available, but I need it. :frowning:

It is my goal to make the sinelon functon from demoreel to an hsv array. I have solved it with this code, but the last 2 dimming leds semms to be purple and not red. Any idea to improve this?

for(uint8_t i=0;i<NUM_LEDS;i++)
{
	nscale8x2(Stripe_VL->CHSV_led[i].val,useless,255-5);		
}

int pos = beatsin8(25,0,NUM_LEDS);

Stripe_VL->CHSV_led[pos].hue=qadd8(Stripe_VL->CHSV_led[pos].hue,255);
Stripe_VL->CHSV_led[pos].sat=qadd8(Stripe_VL->CHSV_led[pos].sat,255);
Stripe_VL->CHSV_led[pos].val=qadd8(Stripe_VL->CHSV_led[pos].val,255);

Would something like this work in place of your nscale8 line?
leds[i] -= CHSV(0, 0, 5); // reduce value by 5

-= isn’t available in this case and will produce an wrap around when it is 0

You sort of want

hsvleds[i].v = hsvleds[i].v - 5;

but with protection from going negative or wrapping around. Luckily, FastLED provides a subtraction function that bottoms out at zero and prevents underflow. It’s “qsub8”, and you can use it like this:

hsvleds[i].v = qsub8( hsvleds[i].v, 5);

That will give a linear fade (-5 each time), and bottom out at zero.

Another approach would be to fade by a fraction each time, which is what fadeToBlackBy does. For that, you’d do something like this:

hsvleds[i].v = scale8( hsvleds[i].v, 250);

“scale8” takes a fraction to scale down TO (eg 250/256ths in this example), not a fraction to scale down BY (6/256ths) the way fadeToBlackBy does. fadeToBlackBy basically does scale8( led, 255-fadeAmount). So here you’re doing the same thing, just to the “v” brightness of an HSV value.

Thanks Mark. I have solved it in this way.

for(uint8_t i=0;i<num_leds;i++)
{
nscale8x2(this->led_array_stripe->CHSV_led[i+this->start_led].val,useless,255-this->fade_amount);
}

	int pos = beatsin16(this->bpm,0,num_leds);


	//Stripe_VL->CHSV_led[pos].hue=qadd8(Stripe_VL->CHSV_led[pos].hue,120);
	//Stripe_VL->CHSV_led[pos].sat=qadd8(Stripe_VL->CHSV_led[pos].sat,255);
	// Stripe_VL->CHSV_led[pos].val=qadd8(Stripe_VL->CHSV_led[pos].val,100);//////
	this->led_array_stripe->CHSV_led[pos+this->start_led].hue=this->color;
	this->led_array_stripe->CHSV_led[pos+this->start_led].val=this->light_value*light_value_multiplikator;

But I think I will improve it like your way.