Rainbow effect (no sound detected) to music activated led bounce

Hello All!

I'm trying to create a rainbow flow effect on these (Adafruit NeoPixel Digital RGB LED Strip 144 LED) strips. But I also attached a Sound Sensor and when it detects sound I want it to flow out (like leds bounce out and back) to the beat of the music when detected.

Any Ideas on what I'm doing wrong? Thanks

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define lightCount 144

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_HZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);



//fadeThickness = 0;  // CHANGE THICKNESS (0-10)

int vol = 0;
float total = 0;
int fadeCol = 0;
int val[25];
int volLast = 0;
int fadeAmt = 0;
int counter = 0;




void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
//Serial.begin(9600); 
}

void loop() {
  fadeCol = 0;
total = 0;

  for (int i = 0; i < 80; i++){
      counter = 0;
       do{
      vol = analogRead(A0);
 
      counter = counter + 1;
      if (counter > 500){
         rainbowCycle(10);
        
      }
    }while (vol == 0);
    
    total = total + vol;
 
  }
  
  vol = total / 80;
// Serial.println(vol);
  
  vol = map(vol,20,255,0,20);
  
  
  if (volLast > vol) {
    vol = volLast - 4;
  }
  
  volLast = vol;
  fadeAmt = 0;
   
//   Serial.print(vol);
  for (int i = 0; i<25;i++){
    
   
 
    if (i < vol){ 
    
          
         
         strip.setPixelColor((i+25), strip.Color(255,0,0));
         strip.setPixelColor((25-i), strip.Color(255,0,0));
    }
    else if (i < (vol + 8)) {
      
         strip.setPixelColor((i+25), strip.Color(0,255,0));
         strip.setPixelColor((25-i), strip.Color(0,255,0));
      
    }
    else
    {
       
      
         strip.setPixelColor((i+25), strip.Color(0,0,255));
         strip.setPixelColor((25-i), strip.Color(0,0,255));

      
    }
  }
    
 
    
  
  
  
  strip.show();
  
}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
     vol = analogRead(A0);
     if (vol> 10) {
       
      return;
       
     }
    
    
  }
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

You've more or less said what you want it to do. You haven't said anything at all about what it is doing.

You haven't said what type of sound sensor you have and in that code I can't see any attempt to do anything with any sound sensor.

Steve

Sorry, I’m using this sound sensor (High Sensitivity Sound Microphone Sensor Detection Module For Arduino AVR PIC)

And this code was originally set up to receive info in from the headphone jack on the computer through A0. So I guess stupidly I thought I could attach a sound sensor and have the same signal hit A0.

Also right now it is just Stuck on red, not doing anything else. When I put volume next to the sound sensor it does not change at all either. But it's not doing the rainbow sequence or reacting to sound at the moment.

jlpoints70:
Sorry, I’m using this sound sensor (High Sensitivity Sound Microphone Sensor Detection Module For Arduino AVR PIC)

A link would be useful because there are hundreds of things called something like that. Some of them only have digital outputs which would make them useless for you.

You need to put some Serial.prints in to see what values you are actually getting for vol and total.

Steve