Skip to content

Instantly share code, notes, and snippets.

@focalintent
Created October 26, 2016 18:39
Show Gist options
  • Save focalintent/2e2c717d7360c939f75a23e7b3a7b72b to your computer and use it in GitHub Desktop.
Save focalintent/2e2c717d7360c939f75a23e7b3a7b72b to your computer and use it in GitHub Desktop.
Quick demo of what frame interpolation might look like
#include <FastLED.h>
#define NUM_LEDS 60
// how many frames per second you want your animation to be. Your total
// update rate will be ANIM_FPS * STEPS
#define ANIM_FPS 30
// the number of steps you want between each frame - should be a power
// of 2 to keep things sane - e.g. 2,4,8,16,32,64
#define STEPS 8
#define SCALE_PER_STEP (256 / STEPS)
CRGB leds[NUM_LEDS};
CRGB old_frame[NUM_LEDS];
CRGB next_frame[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, 6>(leds, NUM_LEDS).setDither(BINARY_DITHERING);
}
void render_next_frame() {
// draw/copy what you want the next frame to be into the next_frame
// array
}
// note - this is not the most optimized that it could be, to make
// what's going on here a bit clearer
void loop() {
static uint8_t cur_step;
EVERY_N_MILLISECONDS(1000 / (ANIM_FPS * STEPS) ) {
if(cur_step == 0) {
for(int i = 0; i < NUM_LEDS; i++) { old_frame[i] = next_frame[i]; }
render_next_frame();
}
blend(old_frame, next_frame, leds, NUM_LEDS, cur_step * SCALE_PER_STEP);
FastLED.show();
cur_step++;
if(cur_step == STEPS) { cur_step = 0; }
} else {
// keep driving show for the temporal dithering
FastLED.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment