1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
}
|