Skip to content

Commit

Permalink
Big update to soundmems_demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
atuline committed Sep 1, 2018
1 parent 10322ec commit b40daea
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 49 deletions.
31 changes: 31 additions & 0 deletions soundmems_demo/besin.h
@@ -0,0 +1,31 @@
#ifndef besin_H
#define besin_H

void besin() { // Add a Perlin noise soundbar. This looks really cool.

// Local definitions


// Persistent local variables


timeval = 30; // Our EVERY_N_MILLIS_I timer value.


// This works.
leds[NUM_LEDS/2] = ColorFromPalette(currentPalette, millis(), sampleavg, NOBLEND);
leds[NUM_LEDS/2-1] = ColorFromPalette(currentPalette, millis(), sampleavg, NOBLEND);


// leds[NUM_LEDS/2] = ColorFromPalette(currentPalette, sampleavg, beatsin8(sampleavg,0,255), NOBLEND);
// leds[NUM_LEDS/2-1] = ColorFromPalette(currentPalette, sampleavg, beatsin8(sampleavg,0,255), NOBLEND);


waveit(); // Move the pixels to the left/right, but not too fast.

// fadeToBlackBy(leds+NUM_LEDS/2-1, 2, 128); // Fade the center, while waveit moves everything out to the edges.
fadeToBlackBy(leds, NUM_LEDS, 2);

} // besin()

#endif
8 changes: 4 additions & 4 deletions soundmems_demo/fillnoise8.h → soundmems_demo/fillnoise.h
@@ -1,7 +1,7 @@
#ifndef FILLNOISE8_H
#define FILLNOISE8_H
#ifndef FILLNOISE_H
#define FILLNOISE_H

void fillnoise8() { // Add a Perlin noise soundbar. This looks really cool.
void fillnoise() { // Add a Perlin noise soundbar. This looks really cool.

// Local definitions
#define xscale 160
Expand Down Expand Up @@ -30,6 +30,6 @@ void fillnoise8() {

fadeToBlackBy(leds+NUM_LEDS/2-1, 2, 128); // Fade the center, while waveit moves everything out to the edges.

} // fillnoise8()
} // fillnoise()

#endif
45 changes: 45 additions & 0 deletions soundmems_demo/noisefiretest.h
@@ -0,0 +1,45 @@
#ifndef NOISEFIRETEST_H
#define NOISEFIRETEST_H

void noisefiretest() { // Create fire based on noise and sampleavg.

// Local definitions
#define xscale 20 // How far apart they are
#define yscale 3 // How fast they move

// Temporary local variable
uint16_t index = 0; // Current colour lookup value.

timeval = 10; // Our EVERY_N_MILLIS_I timer value.

currentPalette = CRGBPalette16(CHSV(0,255,2), CHSV(0,255,4), CHSV(0,255,8), CHSV(0, 255, 8), // Fire palette definition. Lower value = darker.
CHSV(0, 255, 16), CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::DarkOrange,CRGB::DarkOrange, CRGB::Orange, CRGB::Orange,
CRGB::Yellow, CRGB::Orange, CRGB::Yellow, CRGB::Yellow);

for(int i = 0; i < NUM_LEDS; i++) {

// Serial.print(i);
// Serial.print(" ");
index = inoise8(i*xscale,millis()*yscale*NUM_LEDS/255); // X location is constant, but we move along the Y at the rate of millis(). By Andrew Tuline.
// Serial.print(index);
// Serial.print(" ");

// index = (255 - *i*128/NUM_LEDS); // Now we need to scale index so that it gets blacker as we get close to one of the ends

index = (255 - i*256/NUM_LEDS) * index / 128; // Now we need to scale index so that it gets blacker as we get close to one of the ends


// Serial.print(index);
// Serial.println(" ");


leds[NUM_LEDS/2-i/2+1] = ColorFromPalette(currentPalette, index, sampleavg, NOBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
leds[NUM_LEDS/2+i/2-1] = ColorFromPalette(currentPalette, index, sampleavg, NOBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.

} // The higher the value of i => the higher up the palette index (see palette definition).


} // noisefiretest()

#endif
47 changes: 47 additions & 0 deletions soundmems_demo/noisepal.h
@@ -0,0 +1,47 @@
#ifndef NOISEPAL_H
#define NOISEPAL_H

void noisepal() { // Create fire based on noise and sampleavg.

// Local definitions
#define xscale 20 // How far apart they are
#define yscale 3 // How fast they move

// Temporary local variable
uint16_t index = 0; // Current colour lookup value.

timeval = 10; // Our EVERY_N_MILLIS_I timer value.

/* currentPalette = CRGBPalette16(CHSV(0,255,2), CHSV(0,255,4), CHSV(0,255,8), CHSV(0, 255, 8), // Fire palette definition. Lower value = darker.
CHSV(0, 255, 16), CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::DarkOrange,CRGB::DarkOrange, CRGB::Orange, CRGB::Orange,
CRGB::Yellow, CRGB::Orange, CRGB::Yellow, CRGB::Yellow);
*/


for(int i = 0; i < NUM_LEDS; i++) {

// Serial.print(i);
// Serial.print(" ");
index = inoise8(i*xscale,millis()*yscale*NUM_LEDS/255); // X location is constant, but we move along the Y at the rate of millis(). By Andrew Tuline.
// Serial.print(index);
// Serial.print(" ");

// index = (255 - *i*128/NUM_LEDS); // Now we need to scale index so that it gets blacker as we get close to one of the ends

index = (255 - i*256/NUM_LEDS) * index / 128; // Now we need to scale index so that it gets blacker as we get close to one of the ends


// Serial.print(index);
// Serial.println(" ");


leds[NUM_LEDS/2-i/2+1] = ColorFromPalette(currentPalette, index, sampleavg, NOBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
leds[NUM_LEDS/2+i/2-1] = ColorFromPalette(currentPalette, index, sampleavg, NOBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.

} // The higher the value of i => the higher up the palette index (see palette definition).


} // noisepalt()

#endif
24 changes: 24 additions & 0 deletions soundmems_demo/noisewide.h
@@ -0,0 +1,24 @@
#ifndef NOISEWIDE_H
#define NOISEWIDE_H

void noisewide() {

timeval = 10; // Our EVERY_N_MILLIS_I timer value.

uint8_t tempsamp = constrain(sampleavg/2,0,NUM_LEDS/2);

memset(leds, 0, NUM_LEDS * 3); // Quick clearing of the LED's.

for (int i=0; i<tempsamp; i++) {

uint8_t index = inoise8(i*sampleavg+millis(), 5000+i*sampleavg);
// index = inoise8(i*20,millis()*3*NUM_LEDS/255);

leds[NUM_LEDS/2-i] = ColorFromPalette(currentPalette, index, sampleavg, currentBlending);
leds[NUM_LEDS/2+i] = ColorFromPalette(currentPalette, index, sampleavg, currentBlending);

}

} // noisewide()

#endif
19 changes: 11 additions & 8 deletions soundmems_demo/onesine.h
Expand Up @@ -9,27 +9,30 @@ void onesine() {
// Local variables. Play around with these.
uint8_t allfreq = 32; // You can change the frequency, thus distance between bars. Wouldn't recommend changing on the fly.
uint8_t thiscutoff = 192; // You can change the cutoff value to display this wave. Lower value = longer wave.
uint8_t bgclr = 0; // A rotating background colour.

uint8_t bgbright = 10; // Brightness of background colour.
uint8_t colorIndex;

timeval = 30; // Our EVERY_N_MILLIS_I timer value.

thiscutoff = beatsin8(12,64, 224);
// thiscutoff = beatsin8(12,64, 224);

thiscutoff = 255 - sampleavg;


thisphase += sampleavg/2; // Move the sine waves along as a function of sound.
// thisphase += sampleavg/2; // Move the sine waves along as a function of sound.

thisphase = beatsin16(20,-600, 600);


colorIndex = millis() >> 4; // millis() can be used for so many things.

for (int k=0; k<NUM_LEDS-1; k++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
for (int k=0; k<NUM_LEDS; k++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
int thisbright = qsuba(cubicwave8((k*allfreq)+thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
leds[k] = CHSV(bgclr, 255, bgbright); // First set a background colour, but fully saturated.
leds[k] += ColorFromPalette( currentPalette, colorIndex, thisbright, currentBlending); // Let's now add the foreground colour. By Andrew Tuline.
leds[k] = ColorFromPalette( currentPalette, colorIndex, thisbright, currentBlending); // Let's now add the foreground colour. By Andrew Tuline.
colorIndex +=3;
}

bgclr++; // Rotate the background colour. Colours are limited because the brightness is so low.

addGlitter(sampleavg/2); // Add glitter based on sampleavg. By Andrew Tuline.

} // onesine()
Expand Down
2 changes: 1 addition & 1 deletion soundmems_demo/pixel.h
Expand Up @@ -8,7 +8,7 @@ void pixel() {

timeval = 0; // Our EVERY_N_MILLIS_I timer value.

currLED = (currLED+1) % (NUM_LEDS-1); // Cycle through all the LED's. By Andrew Tuline.
currLED = (currLED+1) % (NUM_LEDS); // Cycle through all the LED's. By Andrew Tuline.

CRGB newcolour = ColorFromPalette(currentPalette, oldsample, oldsample, currentBlending); // Colour of the LED will be based on oldsample, while brightness is based on sampleavg.
nblend(leds[currLED], newcolour, 192); // Blend the old value and the new value for a gradual transitioning.
Expand Down
22 changes: 22 additions & 0 deletions soundmems_demo/pixels.h
@@ -0,0 +1,22 @@
#ifndef PIXELS_H
#define PIXELS_H

void pixels() {

// Persistent local variable
static uint16_t currLED; // Persistent local value to count the current LED location.

timeval = 50; // Our EVERY_N_MILLIS_I timer value.

currLED = beatsin8(16,0,10);

for (int i=0; i<NUM_LEDS; i++) {

CRGB newcolour = ColorFromPalette(currentPalette, oldsample+i*8, sampleavg, currentBlending); // Colour of the LED will be based on oldsample, while brightness is based on sampleavg.
nblend(leds[(i+currLED)%NUM_LEDS], newcolour, 192); // Blend the old value and the new value for a gradual transitioning.

}

} // pixels()

#endif
2 changes: 1 addition & 1 deletion soundmems_demo/rainbowg.h
Expand Up @@ -8,7 +8,7 @@ void rainbowg() {
uint8_t beatB = beatsin8(13, 0, 255);
uint8_t beatC = beatsin8(11, 0, 255);

currentPalette = PartyColors_p;
// currentPalette = PartyColors_p;

for (int i=0; i < NUM_LEDS; i++) {
int colorIndex = (beatA+beatB+beatC)/3 * i * 4 / NUM_LEDS;
Expand Down

0 comments on commit b40daea

Please sign in to comment.