Fade loop trouble- RGB synced with WS2812 LEDS

Hello fellow tinkerers! I’m working on getting some RGB strips to fade in and out in sync with a color wipe pattern on the WS2812 NeoPixels. I’ve been screwing with this for about 2 days and and starting to get a bit frustrated.

The process needs to check the previous state of the RGB strip and compare it with the new state and decide whether to fade up, fade down, or do nothing for each individual color. For example, the red RGB would fade up with the red color wipe. For the purple wipe, the blue would fade in, but the red RGB, already lit, would remain lit instead of starting over at zero and fading in again.

With this latest attempt the wipes won’t go and there is no fading. I’v tried using less that/greater than operators, if/else statements and even tried using a switch case, but no go. Does anyone have any possible suggestions? I’m open to a whole new approach!

Thanks!

#include <Adafruit_NeoPixel.h>

#define PINA 7    //ws2812 strip a
#define PINB 8    //ws2812 strip b
#define REDPIN 6   //RGB red
#define GREENPIN 5  //RGB green
#define BLUEPIN 3    //RGB blue
#define FADESPEED 5     // make this higher to slow down
#define NUMPIX 26  // number of pixels

// Parameter 1 = number of pixels in strip
// Parameter 2 = 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_a = Adafruit_NeoPixel(NUMPIX, PINA, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(NUMPIX, PINB, NEO_RGB + NEO_KHZ800);

int oldRed;      //previous RGB red value
int oldGreen;    //previous RGB green value
int oldBlue;    //previous RGB blue value

void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  strip_a.begin();
  strip_a.show();     // Initialize all pixels to 'off'
  strip_b.begin();
  strip_b.show();     // Initialize all pixels to 'off'  
  analogWrite(BLUEPIN, 0);     // Initialize RGB strip to 'off'  
  analogWrite(GREENPIN, 0);
  analogWrite(REDPIN, 0);
  Serial.begin(9600);
  oldRed = 0;    //Set initial RGB values to 0
  oldGreen = 0;
  oldBlue = 0;
}

void loop()
{ 

  colorWipe(255,0,0);  //wipe to red
  delay(2500);
  colorWipe(0,255,0); // wipe to green
  delay(2500);
  colorWipe(0,0,255); // wipe to blue
  delay(2500);
  colorWipe(255,255,255); // wipe to white
  delay(2500);
  colorWipe(0,0,0);  // fade to black
  delay(2500);
  sparkle(1000);
}
void colorWipe(int r,int g, int b){

  for(int x = 0; x < NUMPIX; x++){      //incriment counter
    strip_a.setPixelColor(x, r,g,b);      //turn on pixel
    strip_b.setPixelColor(x, r,g,b); 

    Serial.println(x);



    if (r==0 && oldRed==255){                    // if new value is 0 and old value is 255
      int newRed = 255-(x*(255/NUMPIX));        // fade out in as many increments as there are pixels
      analogWrite(REDPIN,newRed);
      if(x = NUMPIX){                           // if all cycles are complete
        oldRed = 0;                              //reset old value to 0
        analogWrite(REDPIN, 0);                //make sure lights are completly off
      }         
    }
    if(r==255 && oldRed==0){
      int newRed = x*(255/NUMPIX);
      analogWrite(REDPIN, newRed);
      if(x = NUMPIX) {
        oldRed = 255;
        analogWrite(REDPIN, 255);

      }
    }




    /*   if (r > oldRed){                    // new value greater than old (fade on)
     int newRed = x*(;        // add another incriment to new red value
     analogWrite(REDPIN,newRed);
     oldRed=newRed;                    //reset old value to 255
     }
     if (r < oldRed);   {           // new value less than old (fade off)
     int newRed=255-(x*10);      // subtract another incriment from new red value
     analogWrite(REDPIN, newRed);  //fade red out
     oldRed=newRed;                    //reset old value to 0
     }
     */
    /*
    if (g >oldGreen){                    // new value greater than old (fade on)
     int newGreen = x*(255/NUMPIX);        // add another incriment to new green value
     analogWrite(GREENPIN,newGreen);
     oldGreen=newGreen;                    //reset old value to 255
     }
     if (g < oldGreen);
     {           // new value less than old (fade off)
     int newGreen=255-(x*(255/NUMPIX));      // subtract another incriment from new Green value
     analogWrite(GREENPIN, newGreen);  //fade Green out
     oldGreen=newGreen;                    //reset old value to 0
     }
     
     if (b > oldBlue){                    // new value greater than old (fade on)
     int newBlue = x*(255/NUMPIX);        // add another incriment to new Blue value
     analogWrite(BLUEPIN,newBlue);
     oldBlue=newBlue;                    //reset old value to 255
     }
     else (b < oldBlue);
     {           // new value less than old (fade off)
     int newBlue=255-(x*(255/NUMPIX));      // subtract another incriment from new Blue value
     analogWrite(BLUEPIN, newBlue);  //fade Blue out
     oldBlue=newBlue;                    //reset old value to 0
     }
     
     */
    delay(100);
    strip_a.show();
    strip_b.show();
  }
}


void sparkle(int d){
  for(int x=0; d > x; x++){    //counter
    int  i;
    int  j;
    int  k;
    i = random(150);
    j = random(150);
    k = random(150);
    strip_a.setPixelColor(i, 175,255,0);
    strip_a.setPixelColor(j, 255,255,255);
    strip_a.setPixelColor(k, 175,175,255);
    strip_b.setPixelColor(i, 175,255,0);
    strip_b.setPixelColor(j, 255,255,255);
    strip_b.setPixelColor(k, 175,175,255);
    strip_a.show();
    strip_b.show();
    delay(30);
    strip_a.setPixelColor(i, 0,0,85);
    strip_a.setPixelColor(j, 0,0,85);
    strip_a.setPixelColor(k, 0,0,85);
    strip_b.setPixelColor(i, 0,0,85);
    strip_b.setPixelColor(j, 0,0,85);
    strip_b.setPixelColor(k, 0,0,85);

  }
}

OK- day 4- I think I have it figured out! If anyone needs to use this, here is the code. I’m having a drink now!

#include <Adafruit_NeoPixel.h>

#define PINA 7    //ws2812 strip a
#define PINB 8    //ws2812 strip b
#define REDPIN 6   //RGB red
#define GREENPIN 5  //RGB green
#define BLUEPIN 3    //RGB blue
#define FADESPEED 5     // make this higher to slow down
#define NUMPIX 26  // number of pixels

// Parameter 1 = number of pixels in strip
// Parameter 2 = 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_a = Adafruit_NeoPixel(NUMPIX, PINA, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(NUMPIX, PINB, NEO_RGB + NEO_KHZ800);

int oldRed;      //previous RGB red value
int oldGreen;    //previous RGB green value
int oldBlue;    //previous RGB blue value

void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  strip_a.begin();
  strip_a.show();     // Initialize all pixels to 'off'
  strip_b.begin();
  strip_b.show();     // Initialize all pixels to 'off'  
  analogWrite(BLUEPIN, 0);     // Initialize RGB strip to 'off'  
  analogWrite(GREENPIN, 0);
  analogWrite(REDPIN, 0);
  Serial.begin(9600);
  oldRed = 0;    //Set initial RGB values to 0
  oldGreen = 0;
  oldBlue = 0;
}

void loop()
{ 

  colorWipe(255,255,0);  //wipe to yellow
  delay(2500); 
  colorWipe(0,255,255);  //wipe to cyan
  delay(2500); 
  colorWipe(255,0,255);  //wipe to purple
  delay(2500);
  colorWipe(255,0,0);  //wipe to red
  delay(2500);
  colorWipe(0,255,0); // wipe to green
  delay(2500);
  colorWipe(0,0,255); // wipe to blue
  delay(2500);
  colorWipe(255,255,255); // wipe to white
  delay(2500);
  colorWipe(0,0,0);  // fade to black
  delay(2500);

}
void colorWipe(int r,int g, int b){

  for(int x = 0; x < NUMPIX; x++)        //incriment counter
  {      
    strip_a.setPixelColor(x, r,g,b);      //turn on pixel
    strip_b.setPixelColor(x, r,g,b); 

    Serial.print("x = ");
    Serial.print(x);
    Serial.print(",  r = ");
    Serial.print(r);
    Serial.print(",  oldRed = ");
    Serial.print(oldRed);

    if (oldRed == 0 && r == 255){       // new value greater than old (fade on)
      int newRed = x*(255/NUMPIX);        // add another incriment to new red value
      analogWrite(REDPIN,newRed);
      Serial.print("  Fade up newRed = ");
      Serial.println(newRed);
      if(x == NUMPIX-1){                      
        oldRed = 255;                      //reset old value to 255
        analogWrite(REDPIN,255);           // Make sure RGB is at full power
      }      
    }

    if (oldRed == 255 && r == 0){            // new value less than old (fade off)
      int newRed=255-(x*(255/NUMPIX));      // subtract another incriment from new red value
      analogWrite(REDPIN, newRed);           
      Serial.print("  Fade DOWN newRed = ");
      Serial.println(newRed);
      if(x == NUMPIX-1){
        oldRed = 0;                            //reset old value to 0
        analogWrite(REDPIN,0);                 // turn red completly off
      }       
    }        




      if (oldGreen == 0 && g == 255){       // new value greater than old (fade on)
        int newGreen = x*(255/NUMPIX);        // add another incriment to new green value
        analogWrite(GREENPIN,newGreen);
        if(x == NUMPIX-1){
          oldGreen = 255;                      //reset old value to 0
          analogWrite(GREENPIN,255);           //turn green completly on
       }      
    }  

      if (oldGreen == 255 && g == 0){         // new value less than old (fade off)
        int newGreen=255-(x*(255/NUMPIX));      // subtract another incriment from new green value
        analogWrite(GREENPIN, newGreen);                  
        if(x == NUMPIX-1){
          oldGreen = 0;                          //reset old value to 0
          analogWrite(GREENPIN,0);               
      }       
    }          

    if (oldBlue == 0 && b == 255){          // new value greater than old (fade on)
      int newBlue = x*(255/NUMPIX);        // add another incriment to new blue value
      analogWrite(BLUEPIN,newBlue);
      if(x == NUMPIX-1){
        oldBlue = 255;                      //reset old value to 255
        analogWrite(BLUEPIN,255);          //Turns blue on to full brightness
      }     
    }  

    if (oldBlue == 255 && b == 0){         // new value less than old (fade off)                                      
      int newBlue=255-(x*(255/NUMPIX));    // subtract another incriment from new blue value
      analogWrite(BLUEPIN, newBlue);      
      if(x == NUMPIX-1){
        oldBlue = 0;                        //reset old value to 0
        analogWrite(BLUEPIN,0);           //turns blue completly off
      }      
    }           

    delay(100);
    strip_a.show();
    strip_b.show();
  }
}