From f7afe20d982fd89569fa927d1404aa1b787f33d6 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Thu, 17 Nov 2016 22:25:19 -0500 Subject: Add NeoPixel program for a fading strip. --- strip/strip.ino | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 strip/strip.ino diff --git a/strip/strip.ino b/strip/strip.ino new file mode 100644 index 0000000..ce9edf8 --- /dev/null +++ b/strip/strip.ino @@ -0,0 +1,38 @@ +#include + +#include + +#define PIN 7 +#define NUM_LEDS 16 + +Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); +// Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_RGBW + NEO_KHZ800); + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' +} + +int32_t g = 0; + +// Gets the intensity for LED `l`. +// s is a step between 0 and 1000. +// l is the led number, between 0 and NUM_LEDS. +float grad(int s, int l, float num_pixels) { + float scaled = s * 16.0 / 1000; + float distance = abs(scaled - l); + float val = 1 - (2/num_pixels) * distance; + return max(0, val); +} + +void loop() { + float num_pixels = 2.8; + for (int i = 0; i < 1000; i++) { + for (int pixel = 0; pixel < 16; pixel++) { + // strip.setPixelColor(pixel, 0, 5, 50); + strip.setPixelColor(pixel, strip.Color(0, 0, grad(i, pixel, num_pixels) * 255)); + } + strip.show(); + delay(1); + } +} -- cgit v1.2.3