#include <Adafruit_NeoPixel.h>
// ----- Change these -----
const int LEN1 = 48; // strip 1 length (LEDs), pin 12
const int LEN2 = 48; // strip 2 length (LEDs), pin 11
const int LEN3 = 48; // strip 3 length (LEDs), pin 10
const int GAP = 6; // density: a new light every GAP LEDs (same on every strip)
const int SOLID = 3; // strip 3: solid amber LEDs at the end
const int FLOW_BRIGHT = 180; // moving lights brightness (0-255)
const int END_BRIGHT = 255; // solid amber end brightness (0-255)
#define SPEED 70 // lower = faster
#define GREEN 0, 255, 0 // This is the color green. Use color picker.
#define AMBER 255, 150, 0 // amber
Adafruit_NeoPixel strip1(LEN1, 12, NEO_GRB + NEO_KHZ800); // forward, amber
Adafruit_NeoPixel strip2(LEN2, 11, NEO_GRB + NEO_KHZ800); // backward, green
Adafruit_NeoPixel strip3(LEN3, 10, NEO_GRB + NEO_KHZ800); // forward green + amber end
const int levels[3] = {255, 120, 40}; // head, tail, tail
int step = 0;
// Makes a colour dimmer: level 255 = full, 0 = off
uint32_t dim(Adafruit_NeoPixel &s, int r, int g, int b, long level) {
return s.Color(r * level / 255, g * level / 255, b * level / 255);
}
// Draws the flowing lights on the first 'len' LEDs of a strip
void drawFlow(Adafruit_NeoPixel &s, int len, int dir, int r, int g, int b) {
for (int i = 0; i < len; i++) {
int pos = (dir == 1) ? i : (len - 1 - i); // position along the flow
int d = ((step - pos) % GAP + GAP) % GAP; // 0 = head, 1-2 = tail
if (d < 3) {
s.setPixelColor(i, dim(s, r, g, b, (long)levels[d] * FLOW_BRIGHT / 255));
}
}
}
void setup() {
strip1.begin();
strip2.begin();
strip3.begin(); // no setBrightness: brightness is set per LED above
}
void loop() {
strip1.clear();
strip2.clear();
strip3.clear();
drawFlow(strip1, LEN1, 1, AMBER); // amber, forward
drawFlow(strip2, LEN2, -1, GREEN); // green, backward
drawFlow(strip3, LEN3 - SOLID, 1, GREEN); // green, forward
for (int i = LEN3 - SOLID; i < LEN3; i++) {
strip3.setPixelColor(i, dim(strip3, AMBER, END_BRIGHT)); // solid amber end
}
strip1.show();
strip2.show();
strip3.show();
step = (step + 1) % GAP;
delay(SPEED);
}