Hey guys,
I am working on editing an existing code for a strand of neopixels. Currently the code starts a red rippling effect from pixel 30 that goes down the strand one by one. There is only one pixel on each side of the center that is lit at a time and I wanted to see if it would be possible to have it where once the "ripple" has passed a pixel that pixel stays lit and then slowly fades. I am a total novice when it comes to coding so anything helps.
Here is the code I am using:
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define Pixels 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
int red, green, blue;
int center = 0;
int step = -1;
float fadeRate = 1;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop () {
if (step == -1) {
center = random(30,30);
red = random(256);
// green = random(256);
// blue = random(256);
step = 0;
}
for(uint16_t l = 0; l < Pixels; l++) {
strip.setPixelColor(l, 0, 0, 0);
}
if (step == 0) {
strip.setPixelColor(center, red, green, blue);
step ++;
} else {
if (Pixels > center + step || center - step > 1) {
strip.setPixelColor(center + step, red*pow(fadeRate, step), 0, 0);
strip.setPixelColor(center - step, red*pow(fadeRate, step), 0,0);
step ++;
} else {
step = -1;
}
}
strip.show();
delay(150);
}