Skip to content

Instantly share code, notes, and snippets.

@SigmazGFX
Forked from StefanPetrick/2animations.ino
Created May 18, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SigmazGFX/5be102be84200b38c21d0986298f1cc4 to your computer and use it in GitHub Desktop.
Save SigmazGFX/5be102be84200b38c21d0986298f1cc4 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment