I have a very little fastled specific question. If I use nblend(HSV Array1,HSV Array 2,k,SHORTEST_HUES); and I count k from 0 to 255 my HSV array 1 on the led stripe seems to have the destination color very early after 100 or 120 of k. is this blend not linear? I came to that, because I have written an led event handler based on a vector and if blend is ready the next effect starts. Theoretically… But in real the new blend color is on the stripe and I have to wait until the next Effekt starts… Thanks for your help
[Edit: I did the math wrong, and think I fixed it now]
Hi Lars- thanks for the question.
I reviewed the code for HSV nblend, and after some consideration, I think it does what I’d expect it to do.
So if I understand correctly, you’re calling nblend inside a loop (k from 0…255). Are you filling the two HSV arrays each time with new values before you call nblend? The reason I ask is that nblend modifies the first array in place.
So, if you repeatedly call nblend… well, let me give an example. Imagine that each pixel array, A and B, is actually just one value.
Start:
A=0 B=255
nblend 10%, and now:
A=25 B=255
This is what you would expect.
But if you don’t reset A back to zero, then the next time you try to nblend by a larger amount, say 20% this time:
A=25 B=255
nblend( A, B, 20%)
… delta between 255 and 25 is 230
… 20% of 230 is 46
… so new answer is 25 + 46:
A=71 B=255
This is because this time you were blending 20% of the way between 25 and 255, not blending 20% of the way between 0 and 255.
If you then try to nblend an additional 30%, you get this:
A=71 B=255
nblend( A, B, 30%)
… delta between 71 and 255 is 184
… 30% of 184 is 55
… so new answer is 71 + 55 = 126
A=126 B=255
because you asked it to blend 30% of the way between 71 and 255, not 30% of the way between 0 and 255.
So, this was the one thought I had. Are you resetting new values into Array 1 each time through the loop, or are the blends ‘accumulating’ as in the example here? If that’s not it, could you share some code?
If you can’t ‘reset’ Array 1 each time through the loop for whatever reason, you could also have a third array, and ‘blend’ into it each time through the loop, leaving Array 1 and Array 2 untouched.
(oops, borked the math above, fixed it now I think)
You are right I don’t reset the values. Now I have got it. Thanks. So I think I should use blend instead of nblend…
Ah, ok, good! Let us all know if you get it working with plain ‘blend’!
I can test it on Tuesday. I will post it then… Thanks Mark
@Mark_Kriegsman
I have solved it with blend. Thanks.
for(uint8_t i=0;i<num_leds;i++)
{
actual_led_stripe=blend(old_array,destination_array],k,SHORTEST_HUES);
}