Hello together, sorry for my bad explanation of my problem a few days before.

Hello together, sorry for my bad explanation of my problem a few days before. I will try it one more time a little bit easier.

  1. What is my project?
    I have installed 2 or more Led Stripes in my car one from the footwell of the driver side up to under the door. The same on the co driver side with another Led Stripe.

  2. What is my goal in a simple way?
    In a simple way I have a specific color or gradient in the footwell and if I open the door I want to blend to another color(colorarray) in the footwell and if I close the door the leds should blend back to the old color (colorarray).

  3. Specials
    Blending should be slowly and fluently and if the blending isn’t ready and I close or open the door it should be blend seamless–> it has to store the values.
    I have 4 doors and all can be open simutanously and blending should work also very fine. All should work parallel, thats why I increase the blending level only by one each cycle.

  4. What I have done
    I have written an function and a sketch where I have these functionality, but the code is big and I used a lot of variables to control the blending (blend up, blend down, first cycle…). → when I have 4 doors I have to multiply this and this isn’t very clear and a lot of code. I want more structure…

  5. Thoughts on this
    My actual thoughts are to make a class with an object for every door where every door has it’s methods and variables. There I can store the information and create easily new objects, but I don’t know how this exactly works.

All in all, maybe someone of you has an easier way to solve this problem I would be very happy or you can help me with the architecture how to handle the classes…

Thanks for your help!!
Any suggestions?
@Kev_Zhu @Mark_Kriegsman

////////////////////////////////////CODE////////////////////////////////

Some code extracts:
blend up function:

// blend up
uint8_t Licht_hochdimmen(uint8_t k, uint8_t i_Stripe_num, uint8_t i_start_led, uint8_t i_num_led, CHSV led_array)
{

// first blend cycle and last blend complete
if(k==0 && b_Licht_dimm_fertig)
{
	// copy startvalue
	memcpy8(leds_startvalue_chsv+i_start_led,leds_chsv+i_start_led,(i_num_led*3)); // Dest, Source, Bytes 


	memcpy8(leds_nextblend+i_start_led,leds_chsv+i_start_led,(i_num_led*3)); // Dest, Source, Bytes


}
if(k==0 &&!b_Licht_dimm_fertig) // blend down wasnt complete --> modified start value
{
	memcpy8(leds_nextblend+i_start_led,leds_chsv+i_start_led,(i_num_led*3)); // Dest, Source, Bytes
}

b_Licht_dimm_fertig=false; // Information schreiben, dass aktuell gedimt wird, damit nicht das array kopiert wird // blend active --> not copy the array

// blending of colors
for(uint8_t i=0;i<i_num_led;i++)
	{
		leds_chsv[i+i_start_led]=blend(leds_nextblend[i+i_start_led],led_array[i],k, SHORTEST_HUES);
		
	}





if(k >= 254)
{
	k=0;

	b_Licht_dimm_fertig=true;
	b_Licht_up=false;
}
else
{
	k=k+2;
}


// return counter value
return k;

}

Call of the function in loop:

// interrupt from button down
if(b_Licht_active && b_Licht_up)
{
{
// create the blend color array
CHSV Test[3];
fill_rainbow(Test,3,0,10);
///

		// counter value of blending level
		//light dimm_up(count value,stripe_num,start_led,num_leds,ledarray);
		Licht_Step=Licht_hochdimmen(Licht_Step,0,2,3,Test);
		//Licht_time=0;
	}

}

@Lars_Walpurgis

In my opinion, you may be over-complicating things (don’t we all do that in this particular community?!).

There is built in functionality for blending a particular palette towards another.

I would assign a palette to the default colors you’d like when closed, and poll for a door opening. When you get the door state as open, you fill the palette you’re blending towards with the desired colors, and bam, you’re off.

Likewise, when the door is closed, it will default to the normal colors.

The transition is seamless, smooth and most of all, easy :slight_smile:

As an example, here is @Mark_Kriegsman 's code on the functionality of nblendPaletteTowardPalette.

I agree with Jarrod, looks like you do not have so many LEDs per door here. 4 doors X 20 LEDs ? A few more inside the car…

If you are using a Teensy, so you should have plenty of ram and program space to do everything you want. Don’t worry about using too many variables or using simple programming methods for now, just make it work… You can always come back, add structure, create some efficient classes and clean it all up after !

Thanks @JP_Roy ​ the led count isn’t the problem. I am using a teensy so the program space isn’t a problem. The structure is problematic And efficientcy. I haven’t played so much with palette do you think this is the right way? At the moment I only work with nblend

Hi @Lars_Walpurgis , people will look at the awesome light effect when your car door is opened or closed they will not care at all about the ‘problematic structure’ that may or may not be behind it !
Ok, maybe you do, maybe some others here do also but I personally could not care less !!
I am not an expert on palettes but they are very efficient and give you access to a large array of colors and take only a small amount of memory. They may be useful in your case so do experiment with them specially that functionality of…
nblendPaletteTowardPalette
as recommended by Jarrod.
Again… just use whatever works !

Thanks @JP_Roy ​ I will have a look at the palette code.

@Lars_Walpurgis
I have a few questions for you…

  1. When the car door is closed, can you still see the lights from inside the car ?
  2. If yes, are the LEDs stable wit a single color or are they continuously changing ? how ?

Actually, I would ask the same question when the doors are open for some time…

  1. Are the LEDs stable with a single color or are they continuously changing ? how ?

@JP_Roy ​ 1) when the door is closed you can’t see the Leds under the door but you can see the Leds in the footwell and into the speaker. 2) I think mostly they have a single color or a gradient of colors. But I will also run some effects and maybe if I close the door the effect stops and all Leds ( which will have different color and value ) should blend to the old array of colors. This should be possible with open or close the doors. And the code should be flexible with handling this.