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