Music visualizer with the envelope follower circuit and digital LED strip.

Hello,

I just got a digital LED strip and decided to upgrade my music reactive lights.

This is the circuit - Read 3.5mm audio jack volume values with Arduino UNO. - Audio - Arduino Forum

Code:

#include <Adafruit_NeoPixel.h>
 
#define PIN      6
#define N_LEDS 60
 int analogPin = A5;
                   
int val = 0;
int last = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
    Serial.begin(9600);  
  strip.begin();
}
 
void loop() {
   val = analogRead(analogPin);  // read the input pin
Serial.println(val);
 
  for (int i = 0; i < val / 3; i++){
     Serial.println(i);
    if (i <= 15){
          strip.setPixelColor(i, strip.Color(0, i*15, 255));
       strip.show();
    }
    if (i > 15 && i<= 30){
            strip.setPixelColor(i, strip.Color(0, 255, i*15));
       strip.show();
    }
 
    if (i > 30 && i<= 40){
         strip.setPixelColor(i, strip.Color(0,255 , i*15));
       strip.show();
    }
 
       if (i > 40 && i<= 55){
         strip.setPixelColor(i, strip.Color(255, 0, i*15));
       strip.show();
    }
 
    if (i > 55){
          strip.setPixelColor(i, strip.Color(255, 0, 0));
       strip.show();
    }
    last = i;
 
  }
          for (int j = last; j<strip.numPixels(); j++){
   strip.setPixelColor(j, 0);
  }
}

So the problem is the following - with the normal strip I just needed one iteration to light up the whole strip, but with the digital one I need 60 (number of leds) iterations which leads to missing input while iterating thru the whole strip.

Is there a workaround?

Thanks in advance.

Stoil:
Is there a workaround?

You don't need a "workaround". Your code is causing the problem, not the strip, so just fix it! You are calling strip.show() too often. One of the most common mistakes beginners make using addressable strips. Only call strip.show() when you have updated all the leds you want to update (in your case all leds in the strip), not after each individual led is updated.

PaulRB:
You don't need a "workaround". Your code is causing the problem, not the strip, so just fix it! You are calling strip.show() too often. One of the most common mistakes beginners make using addressable strips. Only call strip.show() when you have updated all the leds you want to update (in your case all leds in the strip), not after each individual led is updated.

Thanks for the tip, I fixed that, but it's obviously not the problem here.

edit: problem solved, you can lock. Tried with fastled library and now it works marvelous.

Stoil:
Tried with fastled library and now it works marvelous.

I doubt that's what fixed it. You would get the same problem with FastLED library as you did with NeoPixel library if you call .show() too often. Post your final code, perhaps we can spot the true reason for the improvement.

The show() method doesn't fix it, it doesn't even make a visible difference. The problem lies elsewhere which I cannot figure out for now.
The new code I got from a tutorial I found, which uses FastLED.

The guy's code is much more complex than mine, but I am not familiar with those libraries, nor am I willing to dig too much into it, just no energy left after coding all day at work.

I am not saying the other library won't work - it certainly will, but the problem is not in the show() function.
I played the same song three times with the same volume.
Once with my unnecessary use of show(), once without and once without any code except reading input and printing.
There was no difference between the first two, but without the countless iterations in the third one - there was much more input.

It sounds like, from your response, we will never get to the bottom of it. Too bad, maybe others with similar problems will find this thread and be disappointed we can't tell them what it was that fixed the problem. At least you got to a working solution.

That was the most passive aggressive response I've ever seen on a forum.
You obviously have no input on the matter, thus trying to point out "mistakes" in the code which obviously have no carryover to the underlying problem.
Now, if you feel so strongly about others getting information from this thread - I more than welcome you to solve the problem yourself.
I merely wanted to make my project work and I did it - regardless if I copied someone else's code and adapted it to my needs. I am not going to waste my time trying to solve something that somebody else already solved.
Likewise, I never wanted anybody to solve the problem for me - just give directions.
And here are my directions for others - see if your problem has already been solved and adapt it to your needs.
:slight_smile: Cheers

Sorry. I was too unsubtle in my attempt to get you to share your mistakes and learnings with others. My bad.

There are no learnings. The only "learning" is that yet again I try to do something that's already done by somebody else far more knowledgable than me. To me the problem is obvious but not the solution.
Cheers.

PaulRB:
Sorry. I was too unsubtle in my attempt to get you to share your mistakes and learnings with others. My bad.

Never mind, :sunglasses:

Stoil:
edit: problem solved, you can lock.

Classical. "It's all about me." Once my problem is solved, nothing else matters. :roll_eyes: