Neopixel Vu-meter

Helo, I'm new to arduino programming and i'm using a code i got from someone else but, I want to understand it. everything is working likes it has supposed to work but the last 2 parts is what i don't understand. If you would guys would like to help me by commenting in the code, that would be a big help. I'm also new to the forums feel free to correct me if I did something wrong or missed some details. (Sorry for bad English)

#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(60, PIN, NEO_GRB + NEO_KHZ800);

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

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


}
void VU1() 
{
   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)
   {
      sampleAmplefy = analogRead(0);
      sample = (sampleAmplefy*1.25); // Increase sample for increased animation 
      
      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) {      // from here is the part i don't get
  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);
  }
}

but the last 2 parts is what i don't understand.

The last two parts of what? For what definition of part?

These 2, what are they used for and is does uint32_t do?

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

This may be the blind leading the blind....im no expert

But...uint32 is a definitionnfor an unsigned 32 bit integer.

Now to the location....when you define a function you do in 3 parts.

  1. Define any expected output/return value format. Usually nothibg is returned..so its a void. Ib this case the returned value is a 32 bit integer.

  2. The function name...in this case "wheel"

  3. (in brackets) any parameters you wish to pass to the function, in this case a byte to indicate a position (wheelpos)

Putting it together, the first function seems to be assigning a return colour value based on position.

The second function sets all the pixels in a strip to a set colour "c" for a durafion of "wait"

Ps. The c++ reference site is quite handy at times

One thing I notice is you don't really want to call show() so much. Best is to do all your "drawing" setPixelcolor(); etc. then when you're all done, call show(); to run what you set up in RAM out to the NeoPixels.

typically when I run NeoPixels I structure my loop() like :

void loop() {

   if (time for refresh) {
      
      show();   // Call show to set the pixels to what's in RAM from last time.
      
      reset time for next animation frame.

      Now do all the drawing stuff for the NEXT animation frame.

   }

   Do whatever else needs to be done in loop.

}

Hope this helps.

-jim lee

scrumfled:
This may be the blind leading the blind....im no expert

But...uint32 is a definitionnfor an unsigned 32 bit integer.

Now to the location....when you define a function you do in 3 parts.

  1. Define any expected output/return value format. Usually nothibg is returned..so its a void. Ib this case the returned value is a 32 bit integer.

  2. The function name...in this case "wheel"

  3. (in brackets) any parameters you wish to pass to the function, in this case a byte to indicate a position (wheelpos)

Putting it together, the first function seems to be assigning a return colour value based on position.

The second function sets all the pixels in a strip to a set colour "c" for a durafion of "wait"

Ps. The c++ reference site is quite handy at times

Thank you scrumfled for helping and your explanation makes sense, it really helped.