Last active
August 17, 2023 17:10
-
-
Save StefanPetrick/0c0d54d0f35ea9cca983 to your computer and use it in GitHub Desktop.
Simple example of a video cross fade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
What do I need to try it out?
wonderful trick!
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
Thanks so much, this is fantastic!