Jump to content

Hi guys I am still at an standstill on my led project. I will include a video showing whats happening after its done uploading. Its constantly on the fade effect but seams to switch when the 3.5 mm jack is pluged into my phone and I play a song. When i do that half the strip stays a color and the other half flickers. I have included the code below to. Thanks guys :D. the code is really easy to understand it calls in a library and from there addresses what you are doing.

 

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define lightCount 300

// 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(300, 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(0,255,0));
         strip.setPixelColor((25-i), strip.Color(0,255,0));
    }
    else if (i < (vol + 8)) {
      
         strip.setPixelColor((i+25), strip.Color(255,0,0));
         strip.setPixelColor((25-i), strip.Color(255,0,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);
  }
}

 

Link to comment
https://linustechtips.com/topic/611752-audio-detection-on-leds/
Share on other sites

Link to post
Share on other sites

Hi, I think the problem is that you play the music of your phone and not the pc (that shares ground with the leds and the controller)...

 

Oh and make sure you have the correct led type selected (NEO_KHZ800 or NEO_KHZ400)

 

I manged to figure out the code, now i can move the starting point, add more leds (in my case i have a 5m long ws2812 60led/m stip).

 

If you have any questions, let me know !

Link to comment
https://linustechtips.com/topic/611752-audio-detection-on-leds/#findComment-7926420
Share on other sites

Link to post
Share on other sites

On 6/19/2016 at 8:16 AM, elektron95 said:

Hi, I think the problem is that you play the music of your phone and not the pc (that shares ground with the leds and the controller)...

 

Oh and make sure you have the correct led type selected (NEO_KHZ800 or NEO_KHZ400)

 

I manged to figure out the code, now i can move the starting point, add more leds (in my case i have a 5m long ws2812 60led/m stip).

 

If you have any questions, let me know !

I tried with the pc in different ports and it keeps doing the fade looping

Link to comment
https://linustechtips.com/topic/611752-audio-detection-on-leds/#findComment-7961606
Share on other sites

Link to post
Share on other sites

On 6/19/2016 at 8:16 AM, elektron95 said:

Hi, I think the problem is that you play the music of your phone and not the pc (that shares ground with the leds and the controller)...

 

Oh and make sure you have the correct led type selected (NEO_KHZ800 or NEO_KHZ400)

 

I manged to figure out the code, now i can move the starting point, add more leds (in my case i have a 5m long ws2812 60led/m stip).

 

If you have any questions, let me know !

also is it possibal that the signal from the computer needs to run through an amplifier ?

Link to comment
https://linustechtips.com/topic/611752-audio-detection-on-leds/#findComment-7961622
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×