Skip to content

Instantly share code, notes, and snippets.

@StefanPetrick
Last active August 17, 2023 17:10
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save StefanPetrick/0c0d54d0f35ea9cca983 to your computer and use it in GitHub Desktop.
Save StefanPetrick/0c0d54d0f35ea9cca983 to your computer and use it in GitHub Desktop.
Simple example of a video cross fade
#include "FastLED.h"
#define NUM_LEDS 144
// have 3 independent CRGBs - 2 for the sources and one for the output
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
void setup() {
FastLED.addLeds<APA102, 7, 14, BGR, DATA_RATE_MHZ(12)>(leds, NUM_LEDS);
LEDS.setBrightness(128);
}
void loop() {
// render the first animation into leds2
animationA();
// render the second animation into leds3
animationB();
// set the blend ratio for the video cross fade
// (set ratio to 127 for a constant 50% / 50% blend)
uint8_t ratio = beatsin8(5);
// mix the 2 arrays together
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = blend( leds2[i], leds3[i], ratio );
}
FastLED.show();
}
void animationA() {
// running red stripes
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint8_t red = (millis() / 3) + (i * 5);
if (red > 128) red = 0;
leds2[i] = CRGB(red, 0, 0);
}
}
void animationB() {
// the moving rainbow
for (uint16_t i = 0; i < NUM_LEDS; i++) {
leds3[i] = CHSV((millis() / 4) - (i * 3), 255, 255);
}
}
@isocor
Copy link

isocor commented May 6, 2016

Thanks so much, this is fantastic!

@erbidwak
Copy link

erbidwak commented May 6, 2016

What do I need to try it out?

@SigmazGFX
Copy link

wonderful trick!

@Campfool
Copy link

Brilliant! I've been scratching my head for hours trying to go about this, thanks for the example and the inspiration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment