Skip to content

Instantly share code, notes, and snippets.

@dmiddlecamp
Created October 17, 2015 20:07
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 dmiddlecamp/a50d9043b8f01b9fb2e1 to your computer and use it in GitHub Desktop.
Save dmiddlecamp/a50d9043b8f01b9fb2e1 to your computer and use it in GitHub Desktop.
#define DEFAULT_BRIGHTNESS 1
#define NUM_PIXELS 8
float pixels[NUM_PIXELS];
#define KERNEL_SIZE 5
float kernel[KERNEL_SIZE] = { 1, 0.8, 0.4, 0.8, 1 };
int kernelPos = -1 * KERNEL_SIZE;
void resetPixels() {
for(int i=0;i<NUM_PIXELS;i++) {
pixels[i] = DEFAULT_BRIGHTNESS;
}
}
void calcPixels() {
for(int i=0;i<NUM_PIXELS;i++) {
int pixelIdx = kernelPos + i;
if ((pixelIdx > 0) && (pixelIdx < NUM_PIXELS)) {
int kernelIdx = (i % KERNEL_SIZE);
pixels[pixelIdx] = pixels[pixelIdx] * kernel[pixelIdx];
}
}
}
void setup() {
}
void loop() {
resetPixels();
calcPixels();
kernelPos++;
if (kernelPos > (NUM_PIXELS + KERNEL_SIZE)) {
kernelPos = -1 * KERNEL_SIZE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment