 //***************************************************************
 // Three moving colors.
+//     Uses modulo, %, to make pixel position "loop" around and
+//     stay in valid pixel range.
 //
 // Marc Miller,  Jan. 2019
-//  April 2019 - Updated to use EVERY_N instead of delay().
+//     Apr. 2019 - updated to use EVERY_N instead of delay()
+//     Apr. 2021 - cleaned up some duplicate code
 //***************************************************************
 
 #include "FastLED.h"

#define MASTER_BRIGHTNESS 64
CRGB leds[NUM_LEDS];

int16_t positionRed = NUM_LEDS*2/3;  // Set initial start position of Red
int16_t positionWhite = NUM_LEDS/3;  // Set initial start position of White
int16_t positionBlue = 0;  // Set initial start position of Blue

#define holdTime 120  // Milliseconds to hold position before advancing
int8_t delta = 1;  // 1 or -1.  Sets forward or backwards direction.


//---------------------------------------------------------------


//---------------------------------------------------------------
void loop() {
  
  EVERY_N_MILLISECONDS(holdTime) {

    // Fading tail effect.  Comment out for solid colors
    fadeToBlackBy( leds, NUM_LEDS, 100);
    
    // assign pixel colors
    leds[positionA] = CRGB::Red;
    leds[positionB] = CRGB::Grey;  // Using grey so not as bright
    leds[positionC] = CRGB::Blue;
  
    FastLED.show();  // Show the pixels
   
    // Advance position based on delta, and rollover if needed.
    positionA = ((positionA + delta + NUM_LEDS) % NUM_LEDS);
    positionB = ((positionB + delta + NUM_LEDS) % NUM_LEDS);
    positionC = ((positionC + delta + NUM_LEDS) % NUM_LEDS);

  }//end every_n
  
}
