Neopixel VU meter how to set fall rate

Hi all,

First post here, great forum, have read a lot of great info but cannot find an answer to this. Hoping someone might have a pointer for me…

I have a stereo VU meter that has 60 leds per side, big meter!! Because of the height (2 meters approx) the rate of change in the meter is very sudden. In broadcast there is metering know as PPM (peak program meter) which, as the name suggest, holds the peak. I have found a script for a mono meter that has a peak led and there is a variable that lets me control the rate the peak led falls as. Here is is:

#include <Adafruit_NeoPixel.h>

#define PIN 6

// 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 = Adafruit_NeoPixel(110, PIN, NEO_GRB + NEO_KHZ800);

const int sampleWindow = 10; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
int maximum = 110;
int peak;
int dotCount;
#define PEAK_FALL 4  // Rate of peak falling dot

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

void loop() 
{
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level

   unsigned int signalMax = 0;
   unsigned int signalMin = 100;

   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
   {
      sample = analogRead(0);
      if (sample < 1024)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   
   int led = map(peakToPeak, 0, maximum, 0, strip.numPixels()) -1;
   
   for(int i; i <= led; i++)
   {
     int color = map(i, 0, strip.numPixels(), 0, 255);
     strip.setPixelColor(i, Wheel(color)); 
     
   }
   
   for(int i = strip.numPixels() ; i > led; i--)
   {
     strip.setPixelColor(i, 0); 
     
   }
  strip.show();
  
  if(led > peak)  peak = led; // Keep 'peak' dot at top
   
   if(peak > 0 && peak <= strip.numPixels()-1) strip.setPixelColor(peak,Wheel(map(peak,0,strip.numPixels()-1,0,255)));

   strip.show();
   
// Every few frames, make the peak pixel drop by 1:

    if(++dotCount >= PEAK_FALL) { //fall rate 
      
      if(peak > 0) peak--;
      dotCount = 0;
    }
    
}

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);
  }
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

Other code in next post…

Sorry, the code exceeded the amount of characters allowed. Here is the link to the code

Any suggestions very welcome.

Thanks

Edit: Sorry, should actually say that I am try to work out how to control the rate of descent of the meters in the second script just like the 'Peak Fall' in the first script.

Hi,
Not sure about code, but there's a nice explanation of VU compared to Peak meters:

http://blog.shure.com/shure-tech-tip-vu-and-ppm-audio-meters-an-elementary-explanation/

I THINK you want the VU meter ballistics to have a good-looking large display.

I've been watching VU meters bounce, riding gain on remote broadcasts (starting with "Yale Interprets The News" on WTIC, since 1950. Weird but true.

Hi Terry,

Thanks for the link, interesting read.. Just got delivery of more of the Noepixels, so tempted to make 10mtr high VUs but alas work calls..

A.