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


unsigned char traveller1; // index of moving LED
unsigned char traveller2; // index of moving LED

unsigned long lastTime;  // regulate loop to frame rate
unsigned long passTime1;
unsigned long passTime2;
#define FRAME 14 // frame time in ms
#define STEP 8   // frames per step
#define FADE 9   // fade amount per frame
#define start1 0
#define end1 10
#define start2 12
#define end2 23

unsigned long pass1 = (STEP * (end1 - start1) * FRAME); // used to only flip direction of traveller  when a full pass has compelted
unsigned long pass2 = (STEP * (end2 - start2) * FRAME);

unsigned char bigTick; // count STEP to action
unsigned char fullPass;

bool direction1 = true;
bool direction2 = true;

// 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();

//  no! we neem full brightness to make fading look good. Handle intensity by setting the colour dimmer 
//  strip.setBrightness(191);
}

unsigned char chase(unsigned char start, unsigned char end, unsigned char traveller, bool dir)
{
  traveller++;
    if (traveller >= end - start)
      traveller = 0;

    int colour = strip.Color(255, 0, 0);

    int pix = dir ? traveller + start : end - traveller;

// sorry, did you mean red?
    strip.setPixelColor(pix, 0xff0000);

    return traveller;
}

void loop()
{
  unsigned long now = millis();

  if (now - lastTime < FRAME)
    return;

  lastTime = now;
  if (++bigTick >= STEP) {

    traveller1 = chase(start1, end1, traveller1, direction1);
    traveller2 = chase(start2, end2, traveller2, direction2);
 
    bigTick = 0;
  }

  strip.show();

  ageLEDs();

  if (now - passTime1 < pass1) {
//    return;                    You can't return here without missing the other update!
  }
  else {
    passTime1 = now;
    direction1 = !direction1;
  }

  if (now - passTime2 < pass2) {
//    return;
  }
  else {
    passTime2 = now;
    direction2 = !direction2;
  }
}