Skip to content

Commit

Permalink
Merge pull request #3 from atuline/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
THATDONFC authored Apr 19, 2020
2 parents c337367 + 3f85b12 commit acdbd4b
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 62 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ You can also send me mails to [[email protected]](mailto:dev.aircoookie@g
If WLED really brightens up your every day, you can [![](https://img.shields.io/badge/send%20me%20a%20small%20gift-paypal-blue.svg?style=flat-square)](https://paypal.me/aircoookie)

*Disclaimer:*
If you are sensitive to photoeleptic seizures it is not recommended that you use this software.
In case you still want to try, don't use strobe, lighting or noise modes or high effect speed settings.
As per the MIT license, i assume no liability for any damage to you or any other person or equipment.
If you are prone to photo epileptic seizures, it is not recommended that you use this software.
If you still want to try, **DO NOT** use strobe, lightning or noise modes or high effect-speed settings.
As per the MIT license, I assume no liability for any damage to you or any other person or equipment.

Binary file added wled00/.DS_Store
Binary file not shown.
170 changes: 131 additions & 39 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ uint16_t WS2812FX::mode_bpm()
uint16_t WS2812FX::mode_fillnoise8()
{
if (SEGENV.call == 0) SEGENV.step = random16(12345);
CRGB fastled_col;
// CRGB fastled_col;
for (uint16_t i = 0; i < SEGLEN; i++) {
uint8_t index = inoise8(i * SEGLEN, SEGENV.step + i * SEGLEN);

Expand All @@ -1861,7 +1861,8 @@ uint16_t WS2812FX::mode_fillnoise8()
// fastled_col = ColorFromPalette(currentPalette, index, 255, LINEARBLEND);
// setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
}
SEGENV.step += beatsin8(SEGMENT.speed, 1, 6); //10,1,4
// SEGENV.step += beatsin8(SEGMENT.speed, 1, 6); //10,1,4
SEGENV.step += (SEGMENT.speed >> 4);

return FRAMETIME;
}
Expand Down Expand Up @@ -3378,6 +3379,52 @@ CRGB WS2812FX::pacifica_one_layer(uint16_t i, CRGBPalette16& p, uint16_t cistart
}


//////////////////////////////////////////////////////////////////////////////////////
// Non-reactive by Andrew Tuline //
//////////////////////////////////////////////////////////////////////////////////////

uint16_t WS2812FX::mode_phased(void) { // By: Andrew Tuline

float thisspeed = SEGMENT.speed/32.0;
float allfreq = SEGMENT.intensity/16.0;
static float thisphase = 0; // Phase change value gets calculated.
uint8_t thisrot = 16;

uint8_t thisindex = millis() / thisrot;
thisphase += thisspeed;

for (int i=0; i<SEGLEN; i++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
int thisbright = cubicwave8(((i+1)*allfreq)+thisphase*(i+1)/2);
setPixCol(i, thisindex, thisbright);
thisindex +=256/SEGLEN;
}

return FRAMETIME;

} // mode_phased()



uint16_t WS2812FX::mode_twinkleup(void) { // By: Andrew Tuline - This sure is a LOT shorter than those other twinkle routines.

uint8_t ranstart; // Our first random number is the starting brightness in our sin() calculation.
uint8_t mylen; // The second random number is used as our frequency.
uint8_t mysin; // The result of sin(start+millis/frequency).

random16_set_seed(535); // The randomizer needs to be re-set each time through the loop in order for the 'random' numbers to be the same each time through.

for (int i = 0; i<SEGLEN; i++) {
ranstart = random8(); // The starting value (aka brightness) for each pixel.
mylen = random8(10,20); // The frequency of our sine wave.
mysin = sin8(ranstart + millis()/mylen); // Combined those with millis() which progresses it along.
setPixCol(i, i*20, mysin);
}

return FRAMETIME;

} // mode_twinkleup()


//////////////////////////////////////////////////////////////////////////////////////
// ASOUND01-09 routines by Andrew Tuline //
// ASOUND10-15 routines by Andreas Pleschutznig //
Expand All @@ -3389,7 +3436,7 @@ void WS2812FX::setPixCol(uint16_t location, uint32_t index, uint8_t intensity) {
CRGB color;

if (SEGMENT.palette == 0) { // No palette loaded, so let's use the first colour. . . and white.
uint32_t myClr = color_blend(SEGCOLOR(1), SEGCOLOR(0), intensity); // Scale the brightness of the colour. Not blending to SEGCOLOR(1) with this, just black.
uint32_t myClr = color_blend(SEGCOLOR(1), SEGCOLOR(0), intensity); // Scale the brightness of the colour.
setPixelColor(location, myClr); // This supports RGBW.
} else {
color = ColorFromPalette(currentPalette, index, intensity); // This just uses the palettes and just RGB ones at that.
Expand Down Expand Up @@ -3624,14 +3671,22 @@ uint16_t WS2812FX::mode_asound09(void) { // Fil

#ifndef ESP8266
extern uint16_t FFT_MajorPeak;
double volume = 1;


double mapf(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
#endif


// sound 10: assign a color to the central (starting pixels) based on the predominant frequencies and the volume. The color is being determined by mapping the MajorPeak from the FFT
// and then mapping this to the HSV color circle. Currently we are sampling at 10240 Hz, so the highest frequency we can look at is 5120Hz.
//
// SEGMENT.fft1: the lower cut off point for the FFT. (many, most time the lowest values have very little information since they are FFT conversion artifacts. Suggested value is close to but above 0
// SEGMENT.fft2: The high cut off point. This depends on your sound profile. Most music looks good when this slider is between 50% and 100%.
// SEGMENT.fft3: the "loss" or darkening of pixels as they move outwards. This is the darken factor so silder at 100% == no darkening. Very sensitive.
// SEGMENT.fft3: "preamp" for the audio signal for audio10.
//
// I suggest that for this effect you turn the brightness to 95%-100% but again it depends on your soundprofile you find yourself in.
// Instead of using colorpalettes, This effect works on the HSV color circle with red being the lowest frequency
Expand All @@ -3650,11 +3705,11 @@ uint16_t WS2812FX::mode_asound10(void) {

#ifndef ESP8266
EVERY_N_MILLISECONDS_I(pixTimer, SEGMENT.speed) { // Using FastLED's timer. You want to change speed? You need to . .

pixTimer.setPeriod((256 - SEGMENT.speed) >> 2); // change it down here!!! By Andrew Tuline.

uint16_t dataSize = 4 * SEGLEN; // prepared for RGBW strips, even though we are currently only using RGB strips
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed

uint32_t* leds = reinterpret_cast<uint32_t*>(SEGENV.data);

Expand All @@ -3663,7 +3718,11 @@ uint16_t WS2812FX::mode_asound10(void) {

fade2black(fade);

int pixVal = sampleAvg * SEGMENT.intensity / 256;
double sensitivity = mapf(SEGMENT.fft3, 1, 255, 1, 10);
int pixVal = sampleAvg * SEGMENT.intensity / 256 * sensitivity;
if (pixVal > 255) pixVal = 255;
// volume = mapf(SEGMENT.intensity, 0, 255, 1, 5); // read intensity slider

double intensity = map(pixVal, 0, 255, 0, 100) / 100.0; // make a brightness from the last avg

//Serial.println(intensity);
Expand All @@ -3683,7 +3742,9 @@ uint16_t WS2812FX::mode_asound10(void) {
int lowerLimit = 2 * SEGMENT.fft1;
int i = map(FFT_MajorPeak, lowerLimit, upperLimit, 0, 255);
//Serial.printf("%3d %4d %2d\n",SEGMENT.intensity, upperLimit, i);
c = CHSV(i, 240,255 * intensity);
uint16_t b = 255 * intensity;
if (b > 255) b=255;
c = CHSV(i, 240, (uint8_t)b);
}

// Serial.println(color);
Expand Down Expand Up @@ -3730,45 +3791,76 @@ extern uint16_t lastSample;

uint16_t WS2812FX::mode_asound11(void) { // Fire with sound activation
{
uint32_t it = now >> 5; //div 32

if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed

byte* heat = SEGENV.data;

if (it != SEGENV.step)
{
// Step 1. Cool down every cell a little
for (uint16_t i = 0; i < SEGLEN; i++) {
SEGENV.data[i] = qsub8(heat[i], random8(0, (((20 + SEGMENT.speed /3) * 10) / SEGLEN) + 2));
}

// Step 2. Heat from each cell drifts 'up' and diffuses a little
for (uint16_t k= SEGLEN -1; k > 1; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}

// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if (random8() <= SEGMENT.intensity) {
uint8_t y = random8(7);
if (y < SEGLEN) heat[y] = qadd8(heat[y], lastSample * SEGMENT.fft3 / 256);
}
SEGENV.step = it;
}

// Step 4. Map from heat cells to LED colors
for (uint16_t j = 0; j < SEGLEN; j++) {
CRGB color = ColorFromPalette(currentPalette, min(heat[j],240), 255, LINEARBLEND);
setPixelColor(j, color.red, color.green, color.blue);
}
delay(1); // DO NOT REMOVE!
return FRAMETIME;
}
} // mode_asound11()

extern double fftBin[];

uint16_t WS2812FX::mode_asound12(void) {
delay(1);
#ifndef ESP8266
double maxVal = 0;

// determine upper and lower boundaries
int upperLimit = 20 * SEGMENT.fft2;
int lowerLimit = 20 * SEGMENT.fft1;
int frequencyBand = upperLimit-lowerLimit;
int numBins = frequencyBand / 20;
int binsPerLED = SEGLEN/numBins;
while (binsPerLED == 0) {
SEGMENT.fft2--; // Limit upper end
upperLimit = 20 * SEGMENT.fft2;
frequencyBand = upperLimit-lowerLimit;
numBins = frequencyBand / 20;
binsPerLED = SEGLEN/numBins;
}
if ((SEGMENT.fft2 < 255) && (SEGMENT.fft1 > 0)) {
while ((SEGLEN % numBins) != 0) {
if (SEGMENT.fft2 < 255) { // adjust ever so slightly
SEGMENT.fft2++;
} else {
if (SEGMENT.fft1 > 0) {
SEGMENT.fft1--;
} else {
// I hate to do that, can't adjust without falling out of bounds
goto CantAdjust;
}
}
lowerLimit = 20 * SEGMENT.fft1;
upperLimit = 20 * SEGMENT.fft2;
frequencyBand = upperLimit-lowerLimit;
numBins = frequencyBand / 20;
binsPerLED = SEGLEN/numBins;
}
}
CantAdjust:
// Serial.printf("%4d %4d %4d %2d %2d %3d\n",lowerLimit, upperLimit, frequencyBand, numBins, binsPerLED, SEGLEN % numBins);

// Determine max value in bins to normalize
maxVal = 0;
for (int i = SEGMENT.fft1; i < 2*SEGMENT.fft2; i++) {
if (fftBin[i] > maxVal) {
maxVal = fftBin[i];
if (maxVal > 10000)
Serial.printf("-> %6.0f %3d\n",maxVal, i);
}
}
Serial.printf("%6.0f\n", maxVal);
for ( int b = 0; b < numBins; b++) {
if (binsPerLED > 1) {
for ( int i = 0; i < binsPerLED; i++) {

}
} else {

}
}

#else
setPixelColor(0, color_from_palette(0, true, PALETTE_SOLID_WRAP, 1, 0));
#endif
return FRAMETIME;
} // mode_asound12()

Expand Down
12 changes: 9 additions & 3 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )

#define MODE_COUNT 118
#define MODE_COUNT 120

#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
Expand Down Expand Up @@ -219,6 +219,8 @@
#define FX_MODE_ASound13 115
#define FX_MODE_ASound14 116
#define FX_MODE_ASound15 117
#define FX_MODE_PHASED 118
#define FX_MODE_TWINKLEUP 119


// Sound reactive external variables
Expand Down Expand Up @@ -438,6 +440,8 @@ class WS2812FX {
_mode[FX_MODE_ASound13] = &WS2812FX::mode_asound13;
_mode[FX_MODE_ASound14] = &WS2812FX::mode_asound14;
_mode[FX_MODE_ASound15] = &WS2812FX::mode_asound15;
_mode[FX_MODE_PHASED] = &WS2812FX::mode_phased;
_mode[FX_MODE_TWINKLEUP] = &WS2812FX::mode_twinkleup;

_brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black);
Expand Down Expand Up @@ -641,7 +645,9 @@ class WS2812FX {
mode_asound12(void),
mode_asound13(void),
mode_asound14(void),
mode_asound15(void);
mode_asound15(void),
mode_phased(void),
mode_twinkleup(void);

private:
NeoPixelWrapper *bus;
Expand Down Expand Up @@ -729,7 +735,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst",
"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow",
"Heartbeat","Pacifica","Pacifica Pal","ASound01","ASound02","ASound03","ASound04","ASound05","ASound06","ASound07",
"ASound08","ASound09","ASound10","ASound11","ASound12","ASound13","ASound14","ASound15"
"ASound08","ASound09","ASound10","ASound11","ASound12","ASound13","ASound14","ASound15","Phased","Twinkleup"
])=====";


Expand Down
Loading

0 comments on commit acdbd4b

Please sign in to comment.