I am guessing the lerp8by8 function might be good for me here — can

I am guessing the lerp8by8 function might be good for me here — can someone give me an example of how it might work? Or if anyone has any better ideas for linear interpolation between frames?

  memset8(tempBuff, 0, sizeof(tempBuff));   
  memcpy8(tempBuff, buff, sizeof(tempBuff));

  for (int t = 0; t < 32; t++) {
    for (int i = 0; i < NUM_LEDS; i++) {
      for (int x = 0; x < 3; x++) {
          temp[i][x] = map(t, 0, 31, leds[i][x], tempBuff[i][x]);
      }
    }
    //clear leds
    memset8(leds, 0, sizeof(leds));
    //overwrite leds with temp
    memcpy8(leds, temp, sizeof(leds));
    FastLED.show();
    delay(1);
  }

Sorry, I can’t exactly make out what you’re doing in this loop, but there are two ways I can think of to transition between frames: some form of lerp8by8 if you are doing palettes [and the palettes are “linear”] or the blend() function if you are blending CRGBs. Take a look at colorutils.h for blend() documentation!

Thanks Steve.

I am going through every R, G and B value in two buffers and transitioning between them with the map function.

I couldn’t work out how to use the lerp8by8 function before but now realise that it’s something like this:

lerp8by8( 0, 255, 128 )

Where 128 is between 0 and 255. So above would give 128 as the output.

When I use lerp8b8 my RGB values get scaled up — something like (32,0,0) always ends up as (255,0,0) — which is odd.

OK, got it. I understand the code now: 32 frames of your “map()” function, without interpolation implemented yet.

I haven’t done any direct tests on lerp8by8 to understand edge cases (if any?) Your description is exactly what it should be doing and it could just be a code issue?

But really this sounds like a good candidate for using the CRGB structure and doing blends… In other words, change your leds array from byte[NUM_LEDS][3] to CRGB[NUM_LEDS].

(Also I’m not sure why you’re zeroing the LEDs before filling them again? But maybe you have a reason)

Checking the source code the lerp8b8 shouldn’t be giving me 255 output like it is… at least I don’t think so.

This should give me the same result — I think… (the uncommented line versus the commented)

  for (int i = 0; i < NUM_LEDS; i++) {
    for (int x = 0; x < 3; x++) {  
      temp[i][x] = (tempBuff[i][x] + leds[i][x]) / 2;  
      //temp[i][x] = lerp8by8(leds[i][x], tempBuff[i][x], 128);
    }
  }

Yeah, the two lines should be equivalent.
But there are some strange cases where they could be different - for instance, depending on the declared type of your leds or tempBuff arrays, maybe the uncommented line is overflowing or has a sign error, but then gets cast back into a normal range & appears to be working. Whereas I believe lerp8by8 doesn’t get those, and pegs at 0 and 255.

Temp, leds and tempBuff are all CRGB

Hmmm… Odd

CRGB structure has a lerp8 method too – just for kicks try

leds[i].lerp8(tempBuff[i], 128)

but sorry, I don’t get it - not sure why that would be resulting in 255. I’m using it in my code and it hasn’t had that problem. Give blend() a try, too…

Hi all, I’m interested in this as well, but can’t see a “blend()” fn anywhere. Searching the github repo for “blend()” alse returns empty. Have I missed something?

Just found “blend” on the 2.1 branch. https://github.com/FastLED/FastLED/blob/FastLED2.1/colorutils.h

It appears the Github search doesn’t by default include branches.

So I can do my whole averaging loop using just this one line?

blend(leds, tempBuff, temp, 24, 127);

Doesn’t seem to work for me :frowning:

The only thing is that I am “adding” a colour to black.

Ok — so it works if I do this:

CRGB* temp2 = blend(leds, tempBuff, temp, 24, 127);
memcpy8(leds, temp2, sizeof(leds));

So this works great — except that for some reason it’s not doing all my LEDs — it’s missing off the last one. Even though the LED count is 24 (it does the same odd behaviour if I knock the number down to 20)

James

Works fine if I do this:

    CRGB temp2[24];
    for(int x = 0; x < 24; x++) {
        temp2[x] = blend(leds[x], tempBuff[x], i);
    }

@mark_vr Yeah, sorry - most of the discussions here will be about the 2.1 branch, a lot of stuff here is not in master yet…

@James_Carruthers looks like you might want to try nblend(leds, tempBuff, 24, 127) to replace the entire code block you previously posted. (change 127 to "i’ to replace the more recent for loop one)