Led RGB Strip
Led RGB Strip
Led RGB Strip
h>
#include <FastLED.h>
#include <EEPROM.h>
#define PIN 6
#define N_PIXELS 29
#define BG 0
#define COLOR_ORDER GRB // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color
combinations
#define NUM_BALLS 3 // Number of bouncing balls you want (recommend < 7, but 20 is fun in its
own way)
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 vImpact[NUM_BALLS] ; // As time goes on the impact velocity will change, so make an array to store
those values
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;
int sensorDeviationBrightness = 1;
int sensitivityValue = 128; // 0 - 255, initial value (value read from the potentiometer if
useSensorValues = true)
int ledBrightness = 255; // 0 - 255, initial value (value read from the potentiometer if
useSensorValues = true)
int val;
uint8_t thisfade = 2; // How quickly does it fade? Lower = slower fade rate.
//FOR JUGGLE
uint8_t numdots = 4; // Number of dots in use.
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 maxSteps = 8;
int diff;
//background color
void setup() {
FastLED.setBrightness( BRIGHTNESS );
analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
Serial.begin(115200);
pinMode(buttonPin, INPUT);
pinMode(2, OUTPUT);
digitalWrite(buttonPin, HIGH);
digitalWrite(2, HIGH);
tLast[i] = millis();
h[i] = h0;
tCycle[i] = 0;
}
void loop() {
brightnessValue = analogRead(brightnessPin);
ledBrightness = brightnessValue;
strip.setBrightness(ledBrightness);
prevBrightnessValue = brightnessValue;
}
//for mic
uint8_t i;
int n, height;
buttonPushCounter=EEPROM.read(0);
buttonState = digitalRead(buttonPin);
buttonPushCounter++;
Serial.println("on");
Serial.println(buttonPushCounter);
if(buttonPushCounter>=14) {
buttonPushCounter=1;}
EEPROM.write(0,buttonPushCounter);
}
else {
Serial.println("off");
}
}
lastButtonState = buttonState;
switch (buttonPushCounter){
case 1:
buttonPushCounter==1; {
Serial.println("1");
vu(); // Red
break;}
case 2:
buttonPushCounter==2; {
Serial.println("2");
case 3:
buttonPushCounter==3; {
Serial.println("3");
Vu3(); //
break;}
case 4:
buttonPushCounter==4; {
Serial.println("4");
Vu4(); //
break;}
case 5:
buttonPushCounter==5; {
Serial.println("5");
rainbow(150);
break;}
case 6:
buttonPushCounter==6; {
Serial.println("6");
rainbow(20);
break;}
case 7:
buttonPushCounter==7; {
Serial.println("7");
ripple();
break;}
case 8:
buttonPushCounter==8; {
Serial.println("8");
ripple2();
break;}
case 9:
buttonPushCounter==9; {
Serial.println("10");
Twinkle();
break;}
buttonPushCounter==10; {
Serial.println("10");
pattern2();
break;}
buttonPushCounter==11; {
Serial.println("11");
pattern3();
break;}
buttonPushCounter==12; {
Serial.println("12");
Balls(); //
break;}
case 13:
buttonPushCounter==13; {
Serial.println("13");
break;}
}
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
void Vu4() {
uint8_t i;
int n, height;
val = (analogRead(potPin));
if(val<0){
n=n/(val*(-1));
}
if(val>0){
n=n*val;
}
// Calculate bar height based on dynamic min/max levels (fixed point):
greenOffset += SPEED;
blueOffset += SPEED;
}
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);
}
if(peak > 0) peak--;
dotCount = 0;
}
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
void Vu3() {
uint8_t i;
int n, height;
val = (analogRead(potPin));
if(val<0){
n=n/(val*(-1));
}
if(val>0){
n=n*val;
}
// Calculate bar height based on dynamic min/max levels (fixed point):
if (height > peak) peak = height; // Keep 'peak' dot at top
greenOffset += SPEED;
blueOffset += SPEED;
strip.setPixelColor(i, 0, 0, 0);
} else {
strip.setPixelColor(i, Wheel(
));
}
}
strip.show(); // Update strip
dotCount = 0;
}
vol[volCount] = n;
volCount = 0;
}
minLvl = vol[i];
maxLvl = vol[i];
}
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
}
void Balls() {
tCycle[i] = millis() - tLast[i] ; // Calculate the time since the last time the ball was on the ground
// A little kinematics equation calculates positon as a function of time, acceleration (gravity) and intial velocity
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;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
}
strip.show();
delay(wait);
}
}
// HERE
void vu() {
uint8_t i;
int n, height;
val = (analogRead(potPin));
if(val<0){
n=n/(val*(-1));
}
if(val>0){
n=n*val;
}
// Calculate bar height based on dynamic min/max levels (fixed point):
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
// for vertically scaling the output graph (so it looks interesting
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
}
// Input a value 0 to 255 to get a color value.
WheelPos -= 85;
} else {
WheelPos -= 170;
}
void vu2() {
uint8_t i;
int n, height;
val = (analogRead(potPin));
if(val<0){
n=n/(val*(-1));
}
if(val>0){
n=n*val;
}
// Calculate bar height based on dynamic min/max levels (fixed point):
}
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);
}
dotCount = 0;
}
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
//here................
void ripple() {
nextBg = random(256);
}
currentBg++;
} else {
currentBg--;
}
}
center = random(N_PIXELS);
color = random(256);
step = 0;
}
if (step == 0) {
}
else {
Serial.println(pow(fadeRate,step));
}
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){
nextBg = random(256);
}
currentBg++;
} else {
currentBg--;
}
}
} else {
strip.setPixelColor(l, 0, 0, 0);
}
}
center = random(N_PIXELS);
color = random(256);
step = 0;
}
if (step == 0) {
step ++;
}
else {
}
step ++;
}
else {
step = -1;
}
}
strip.show();
delay(50);
// return step;
//}
}
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()
void juggle() { // Several colored dots, weaving in and out of sync with each other
curhue += hueinc;
}
} // juggle()
void ChangeMe() { // A time (rather than loop) based demo sequencer. This gives us full
control over the length of each sequence.
uint8_t secondHand = (millis() / 1000) % 30; // IMPORTANT!!! Change '30' to a different value to change
duration of the loop.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our
'debounce' variable.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
if (secondHand == 0) {numdots=1; faderate=2;} // You can change values here, one at a time , or altogether.
if (secondHand == 20) {hueinc=48; thishue=random8();} // Only gets called once, and not
continuously for the next several seconds. Therefore, no rainbows.
}
} // 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;
}
} 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);
}