Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@isocor isocor commented May 6, 2016

Thanks so much, this is fantastic!

@erbidwak

This comment has been minimized.

Copy link

@erbidwak erbidwak commented May 6, 2016

What do I need to try it out?

@SigmazGFX

This comment has been minimized.

Copy link

@SigmazGFX SigmazGFX commented May 18, 2016

wonderful trick!

@Campfool

This comment has been minimized.

Copy link

@Campfool Campfool commented Nov 30, 2018

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
You can’t perform that action at this time.