//#include <Arduino.h>
# include <Adafruit_NeoPixel.h>
# define LED_COUNT 24 // set to test in wokwi
# define LED_PIN 8
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
# define NTRAVELLERS 2
int start[NTRAVELLERS] = {1, 15}; // start points
int end[NTRAVELLERS] = {10, 20}; // end points
char direction[NTRAVELLERS] = {1, 1}; // start going forward
unsigned char traveller[NTRAVELLERS]; // current index of moving LED as ring index
unsigned long lastTime; // regulate loop to frame rate
# define FRAME 14 // frame time in ms
# define STEP 8 // frames per step
# define FADE 9 // fade amount per frame
unsigned char bigTick; // count STEP to action
unsigned char fullPass;
// reduce all RGB of all LEDs just a little bit
void ageLEDs()
{
unsigned char *blast = strip.getPixels();
for (int ii = 0; ii < (LED_COUNT * 3); ii++, blast++) {
if (*blast < 3) *blast = 0;
else *blast -= 3;
}
}
void setup()
{
Serial.begin(115200);
Serial.println("travel yet?");
strip.begin();
strip.show();
}
void chase(unsigned char theTraveller)
{
traveller[theTraveller] += direction[theTraveller];
if (traveller[theTraveller] >= end[theTraveller]) direction[theTraveller] = -1;
if (traveller[theTraveller] <= start[theTraveller]) direction[theTraveller] = 1;
strip.setPixelColor(traveller[theTraveller], 0xff0000);
}
void loop()
{
unsigned long now = millis();
if (now - lastTime < FRAME)
return;
lastTime = now;
if (++bigTick >= STEP) {
chase(0); // advance each traveller
chase(1);
bigTick = 0;
}
strip.show();
ageLEDs();
}