Vúmetro Arduino
Vúmetro Arduino
h>
#include <FastLED.h>
#define PIN 6
#define N_PIXELS 60
#define BG 0
#define COLOR_ORDER GRB // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new
world of color combinations
float vImpact0 = sqrt( -2 * GRAVITY * h0 ); // Impact velocity of the ball when it hits the
ground if "dropped" from the top of the strip
float tCycle[NUM_BALLS] ; // The time since the last time the ball struck the ground
int pos[NUM_BALLS] ; // The integer position of the dot on the strip (LED index)
float
greenOffset = 30,
blueOffset = 150;
byte
int
maxLvlAvg = 512;
uint8_t faderate = 2; // How long should the trails be. Very low value =
longer trails.
uint8_t curhue = 0;
uint8_t basebeat = 5;
// Twinkle
float redStates[N_PIXELS];
float blueStates[N_PIXELS];
float greenStates[N_PIXELS];
// Vu meter 4
CRGB leds[N_PIXELS];
int myhue = 0;
int lastButtonState = 0;
//Ripple variables
int color;
int center = 0;
int diff;
//background color
void setup() {
FastLED.setBrightness( BRIGHTNESS );
analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
Serial.begin(115200);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
tLast[i] = millis();
h[i] = h0;
tCycle[i] = 0;
}
void loop() {
//for mic
uint8_t i;
int n, height;
// end mic
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println("on");
Serial.println(buttonPushCounter);
if(buttonPushCounter==14) {
buttonPushCounter=1;}
else {
Serial.println("off");
}
lastButtonState = buttonState;
switch (buttonPushCounter){
case 1:
buttonPushCounter==1; {
vu(); // Red
break;}
case 2:
buttonPushCounter==2; {
vu2(); // Red
break;}
case 3:
buttonPushCounter==3; {
Vu3(); //
break;}
case 4:
buttonPushCounter==4; {
Vu4(); //
break;}
case 5:
buttonPushCounter==5; {
rainbow(150);
break;}
case 6:
buttonPushCounter==6; {
rainbow(20);
break;}
case 7:
buttonPushCounter==7; {
ripple();
break;}
case 8:
buttonPushCounter==8; {
ripple2();
break;}
case 9:
buttonPushCounter==9; {
Twinkle();
break;}
case 10:
buttonPushCounter==10; {
pattern2();
break;}
case 11:
buttonPushCounter==11; {
pattern3();
break;}
case 12:
buttonPushCounter==12; {
Balls(); //
break;}
case 13:
buttonPushCounter==13; {
break;}
}
}
strip.setPixelColor(i, c);
strip.show();
delay(wait);
void Vu4() {
uint8_t i;
int n, height;
greenOffset += SPEED;
blueOffset += SPEED;
strip.setPixelColor(N_PIXELS_HALF-i-1, 0, 0, 0);
strip.setPixelColor(N_PIXELS_HALF+i, 0, 0, 0);
else {
strip.setPixelColor(N_PIXELS_HALF-i-1,color);
strip.setPixelColor(N_PIXELS_HALF+i,color);
strip.setPixelColor(N_PIXELS_HALF-peak-1,color);
strip.setPixelColor(N_PIXELS_HALF+peak,color);
}
strip.show(); // Update strip
dotCount = 0;
// minLvl and maxLvl indicate the volume range over prior frames, used
// (e.g. at very low volume levels) the graph becomes super coarse
void Vu3() {
uint8_t i;
int n, height;
greenOffset += SPEED;
blueOffset += SPEED;
if (i >= height) {
strip.setPixelColor(i, 0, 0, 0);
} else {
strip.setPixelColor(i, Wheel(
));
dotCount = 0;
vol[volCount] = n;
minLvl = vol[i];
maxLvl = vol[i];
// minLvl and maxLvl indicate the volume range over prior frames, used
// (e.g. at very low volume levels) the graph becomes super coarse
}
void Balls() {
tCycle[i] = millis() - tLast[i] ; // Calculate the time since the last time the ball was on the
ground
if ( h[i] < 0 ) {
h[i] = 0; // If the ball crossed the threshold of the "ground," put it back on
the ground
vImpact[i] = COR[i] * vImpact[i] ; // and recalculate its new upward velocity as it's old
velocity * COR
tLast[i] = millis();
if ( vImpact[i] < 0.01 ) vImpact[i] = vImpact0; // If the ball is barely moving, "pop" it back up
at vImpact0
pos[i] = round( h[i] * (N_PIXELS - 1) / h0); // Map "h" to a "pos" integer index position on
the LED strip
for (int i = 0 ; i < NUM_BALLS ; i++) leds[pos[i]] = CHSV( uint8_t (i * 40) , 255, 255);
FastLED.show();
leds[pos[i]] = CRGB::Black;
}
}
uint16_t i, j;
strip.show();
delay(wait);
// HERE
void vu() {
uint8_t i;
int n, height;
n = analogRead(MIC_PIN); // Raw reading from mic
else strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150)));
dotCount = 0;
// minLvl and maxLvl indicate the volume range over prior frames, used
// (e.g. at very low volume levels) the graph becomes super coarse
WheelPos -= 85;
} else {
WheelPos -= 170;
void vu2() {
uint8_t i;
int n, height;
strip.setPixelColor(N_PIXELS_HALF-i-1, 0, 0, 0);
strip.setPixelColor(N_PIXELS_HALF+i, 0, 0, 0);
else {
strip.setPixelColor(N_PIXELS_HALF-i-1,color);
strip.setPixelColor(N_PIXELS_HALF+i,color);
}
// Draw peak dot
strip.setPixelColor(N_PIXELS_HALF-peak-1,color);
strip.setPixelColor(N_PIXELS_HALF+peak,color);
dotCount = 0;
// minLvl and maxLvl indicate the volume range over prior frames, used
// (e.g. at very low volume levels) the graph becomes super coarse
//here................
void ripple() {
if (currentBg == nextBg) {
nextBg = random(256);
currentBg++;
} else {
currentBg--;
if (step == -1) {
center = random(N_PIXELS);
color = random(256);
step = 0;
if (step == 0) {
step ++;
else {
Serial.println(pow(fadeRate,step));
if (step > 3) {
step ++;
}
else {
step = -1;
LEDS.show();
delay(50);
return step;
void one_color_allHSV(int ahue, int abright) { // SET ALL LEDS TO ONE COLOR (HSV)
void ripple2() {
if (BG){
if (currentBg == nextBg) {
nextBg = random(256);
currentBg++;
} else {
currentBg--;
} else {
strip.setPixelColor(l, 0, 0, 0);
if (step == -1) {
center = random(N_PIXELS);
color = random(256);
step = 0;
if (step == 0) {
else {
if (step > 3) {
step ++;
else {
step = -1;
strip.show();
delay(50);
// return step;
//}
// Input a value 0 to 255 to get a color value.
WheelPos -= 85;
else {
WheelPos -= 170;
void pattern2() {
} // loop()
void sinelon() {
// a colored dot sweeping back and forth, with fading trails
// Pattern 3 - JUGGLE
void pattern3() {
ChangeMe();
juggle();
} // loop()
curhue += hueinc;
} // juggle()
static uint8_t lastSecond = 99; // Static variable, means it's only defined once.
This is our 'debounce' variable.
lastSecond = secondHand;
} // ChangeMe()
void Twinkle () {
if (random(25) == 1) {
uint16_t i = random(N_PIXELS);
redStates[i] = random(256);
greenStates[i] = random(256);
blueStates[i] = random(256);
} else {
redStates[l] = 0;
if (greenStates[l] > 1) {
} else {
greenStates[l] = 0;
if (blueStates[l] > 1) {
} else {
blueStates[l] = 0;
} else {
strip.setPixelColor(l, 0, 0, 0);
strip.show();
delay(10);
}
// TOO HERE
uint16_t i, j;
strip.show();
delay(wait);