summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-11-17 22:25:19 -0500
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-11-17 22:27:45 -0500
commitf7afe20d982fd89569fa927d1404aa1b787f33d6 (patch)
treec3686a2cf218d97cb14bff3048ee95ff2b1a4739
parent506d463544825696386acf9aa4d572ff3301f7e4 (diff)
Add NeoPixel program for a fading strip.
-rw-r--r--strip/strip.ino38
1 files changed, 38 insertions, 0 deletions
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 <Adafruit_NeoPixel.h>
+
+#include <Adafruit_NeoPixel.h>
+
+#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);
+ }
+}