#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); } }