Neopixel Fade programming issues

hello all,

I’m working on a project and i think i’m really, REALLY close to having the programming complete. But…

What my project entails is a shadowbox where I’m using a Maxbotix LV-EZ1 to turn on the rest of the components when the sensor field is “broken”. The other components I’m using is an UNO/Wave Shield combo, a Trinket, and a set of Neopixels. When the field of the sensor is broken, the Wave will play a random audio file (got that part covered i’m pretty certain) and what i want the Neopixels to do is smoothly fade in as the sensor is tripped, and smoothly fade out at the end of the audio file. (The sensor will also actuate a Trinket, but i have that covered).

When i use different calls/subroutines(?) either nothing will happen, the neopixels will turn on and not the audio, or the audio will turn on and not the neopixels. The best luck i’ve had so far is adjusting one of the subroutines to come fully on/off when the sensor is tripped, which i dont want:

    //FADE IN
    void fadeIn(){     
            if (upDownFlag==0){//if flag is 1 bring up brightness to maxThrob then flip flag

Any idea what to do? I’m sooooo close to finishing this project and I’ve been all over the forums and nothing that i do seems to work, and aside from this past week really, i have no prior programming experience.

Here’s the full program with examples of subroutines that i’ve tried with varying degrees of failure.

    #include <Adafruit_NeoPixel.h>
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, 6, NEO_GRB + NEO_KHZ800);//To change FADE rate, adjust 1st #
    #include <WaveHC.h>
    #include <WaveUtil.h>

    // These should be at the root level, not in a folder.
    PROGMEM char
      file00[] = "0.wav",
      file01[] = "1.wav",
      file02[] = "2.wav",
      file03[] = "3.wav",
      file04[] = "4.wav",
      file05[] = "5.wav",
      file06[] = "6.wav",
      file07[] = "7.wav",
      file08[] = "8.wav",
      file09[] = "9.wav";
    // If adding files above, include corresponding items here:
    PROGMEM const char *filename[] = {
      file00, file01, file02, file03, file04,
      file05, file06, file07, file08, file09 };
    // Sorry for the sillyness, but this is how PROGMEM string
    // arrays are handled.

        //WAVE (Continued)
        #define error(msg) error_P(PSTR(msg))
        SdReader  card;
        FatVolume vol;
        FatReader root;
        FatReader file;
        WaveHC    wave;
        uint8_t   debounce = 0,   // Button debounce counter
              prev     = 255; // Index of last sound played
        int led = 7;
        int sonarPin = A0; //pin connected to analog out on maxsonar sensor
        int inchesAway; // inches away from the maxsonar sensor
        int upDownFlag=0;  //flag used to see if throbing is rising or dropping 0=dropping, 1=rising
        int throbBright=1;// current brightness value
        int maxThrob=255;
        int minThrob=1; //***Set this below 11 to see bug*** (Bug not present so far)


    void setup() {
      pinMode (led, OUTPUT); 
          strip.setBrightness(throbBright); //Start with minimum brightness
          for( int i=0; i<strip.numPixels();i++){ //set all leds to a set color
            strip.setPixelColor(i,255,255,255 ); //Use to adjust color of pixels
; // Initialize all pixels to set color
      if(!card.init())        error("Card init. failed!");
      if(!vol.init(card))     error("No partition!");
      if(!root.openRoot(vol)) error("Couldn't open dir");
      // PgmPrintln("Files found:");
      //digitalWrite(A0, HIGH);     // Enable pullup on button
      randomSeed(analogRead(A1)); // Randomize first sound

    void loop() {

      inchesAway = analogRead(sonarPin) /2; // reads the maxsonar sensor and divides the value by 2
      if(inchesAway < 12) { // Debounced button press
        digitalWrite(led, HIGH);  //Turns on TRINKET
        uint8_t n;
        char    name[20];

        do { // Choose a random file...
          n = random(sizeof(filename) / sizeof(filename[0]));
        } while(n == prev); // ...but don't repeat last one
        prev     = n;                       // Save file #
        debounce = 0;                       // Reset debounce counter
        strcpy_P(name, (char *)pgm_read_word(&filename[n])); // PROGMEM->RAM
        if(wave.isplaying) wave.stop();     // Stop WAV if playing

        if(!, name)) {
        if(!wave.create(file)) {
        };                   // Start playing
        while(wave.isplaying);         // Wait for completion
        sdErrorCheck();      // Check for error during play

        digitalWrite(led, LOW);    //Turns off TRINKET

    void error_P(const char *str) {
      PgmPrint("Error: ");

    void sdErrorCheck(void) {
      if(!card.errorCode()) return;
      PgmPrint("\r\nSD I/O error: ");
      Serial.print(card.errorCode(), HEX);
      PgmPrint(", ");
      Serial.println(card.errorData(), HEX);


    //FADE IN
    void fadeIn(){     
            if (upDownFlag==0){//if flag is 1 bring up brightness to maxThrob then flip flag
            if (throbBright>maxThrob) {
            strip.setBrightness(throbBright); //set brightness
;//Display pixels
    //FADE OUT     
           void fadeOut(){       
           if (upDownFlag==0){//if flag is 1 bring up brightness to maxThrob then flip flag
           if (throbBright<minThrob) {
            strip.setBrightness(throbBright); //set brightness
;//Display pixels

               #define TOTAL_LEDS 60

        void breathe(float MaximumBrightness, float SpeedFactor, float StepDelay)
          // Make the lights breathe
          for (int i = 0; i < 65535; i++) {
            // Intensity will go from 10 - MaximumBrightness in a "breathing" manner
            float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * i));
            // Now set every LED to that color
            for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
              strip.setPixelColor(ledNumber, 0, 0, 255);
            //Wait a bit before continuing to breathe
        //int fadeControl = 255;//will hold the current brightness level
        //int fadeDirection = -1;//change sigen to fade up or down
        //int fadeStep = 10;//delay between updates
       //void fadeControl(){
         //strip.setPixelColor(0, 255, 192, 255);//set the pixel colour
          //strip.setBrightness(fadeControl);//set the pixel brightness
          //fadeControl = fadeControl + fadeDirection;//increment the brightness value
          //if (fadeControl <0 || fadeControl > 255)
          //If the brightness value has gone past its limits...
            //fadeDirection = fadeDirection * -1;//change the direction...
            //fadeControl = fadeControl + fadeDirection;//...and start back.
          //delay(fadeStep);//wait a bit before doing it again.
        while(wave.isplaying);         // Wait for completion

Really? That's going to make it hard to fade LEDs while the music plays.

Instead of doing nothing (that's what the ; means), make the LEDs fade up and down while the music is playing. Or make them fade up to some level, and then fade down after the music ends.