Move tristate_square8 to FX_fcn.cpp
This commit is contained in:
parent
2cc6edd868
commit
1e3834dc3d
@ -3713,45 +3713,19 @@ uint16_t WS2812FX::mode_dancing_shadows(void)
|
|||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Generates a tristate square wave w/ attac & decay
|
|
||||||
* @param x input value 0-255
|
|
||||||
* @param pulsewidth 0-127
|
|
||||||
* @param attdec attac & decay, max. pulsewidth / 2
|
|
||||||
* @returns signed waveform value
|
|
||||||
*/
|
|
||||||
int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) {
|
|
||||||
int8_t a;
|
|
||||||
if (x > 127) {
|
|
||||||
a = -127;
|
|
||||||
x -= 127;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
a = 127;
|
|
||||||
|
|
||||||
if (x < attdec) { //inc to max
|
|
||||||
return (int16_t) x * a / attdec;
|
|
||||||
}
|
|
||||||
else if (x < pulsewidth - attdec) { //max
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
else if (x < pulsewidth) { //dec to 0
|
|
||||||
return (int16_t) (pulsewidth - x) * a / attdec;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Imitates a washing machine, rotating same waves forward, then pause, then backward.
|
Imitates a washing machine, rotating same waves forward, then pause, then backward.
|
||||||
By Stefan Seegel
|
By Stefan Seegel
|
||||||
*/
|
*/
|
||||||
uint16_t WS2812FX::mode_washing_machine(void) {
|
uint16_t WS2812FX::mode_washing_machine(void) {
|
||||||
int8_t speed= tristate_square8((uint16_t) (SEGMENT.speed + 100) * now / 20000, 90, 15) / 15;
|
float speed = tristate_square8(now >> 7, 90, 15);
|
||||||
|
float quot = 32.0f - ((float)SEGMENT.speed / 16.0f);
|
||||||
|
speed /= quot;
|
||||||
|
|
||||||
SEGENV.step += speed;
|
SEGENV.step += (speed * 128.0f);
|
||||||
|
|
||||||
for (int i=0; i<SEGLEN; i++) {
|
for (int i=0; i<SEGLEN; i++) {
|
||||||
uint8_t col = sin8(((SEGMENT.intensity / 25 + 1) * 255 * i / SEGLEN) + SEGENV.step);
|
uint8_t col = sin8(((SEGMENT.intensity / 25 + 1) * 255 * i / SEGLEN) + (SEGENV.step >> 7));
|
||||||
setPixelColor(i, color_from_palette(col, false, PALETTE_SOLID_WRAP, 3));
|
setPixelColor(i, color_from_palette(col, false, PALETTE_SOLID_WRAP, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,6 +487,9 @@ class WS2812FX {
|
|||||||
gamma8(uint8_t),
|
gamma8(uint8_t),
|
||||||
get_random_wheel_index(uint8_t);
|
get_random_wheel_index(uint8_t);
|
||||||
|
|
||||||
|
int8_t
|
||||||
|
tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec);
|
||||||
|
|
||||||
uint16_t
|
uint16_t
|
||||||
ablMilliampsMax,
|
ablMilliampsMax,
|
||||||
currentMilliamps,
|
currentMilliamps,
|
||||||
@ -715,7 +718,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
|
|||||||
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst",
|
"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",
|
"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow",
|
||||||
"Heartbeat","Pacifica","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise",
|
"Heartbeat","Pacifica","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise",
|
||||||
"Flow","Chunchun","Dancing Shadows", "Washing machine"
|
"Flow","Chunchun","Dancing Shadows","Washing Machine"
|
||||||
])=====";
|
])=====";
|
||||||
|
|
||||||
|
|
||||||
|
@ -699,6 +699,32 @@ uint16_t WS2812FX::triwave16(uint16_t in)
|
|||||||
return 0xFFFF - (in - 0x8000)*2;
|
return 0xFFFF - (in - 0x8000)*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generates a tristate square wave w/ attac & decay
|
||||||
|
* @param x input value 0-255
|
||||||
|
* @param pulsewidth 0-127
|
||||||
|
* @param attdec attac & decay, max. pulsewidth / 2
|
||||||
|
* @returns signed waveform value
|
||||||
|
*/
|
||||||
|
int8_t WS2812FX::tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) {
|
||||||
|
int8_t a = 127;
|
||||||
|
if (x > 127) {
|
||||||
|
a = -127;
|
||||||
|
x -= 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x < attdec) { //inc to max
|
||||||
|
return (int16_t) x * a / attdec;
|
||||||
|
}
|
||||||
|
else if (x < pulsewidth - attdec) { //max
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
else if (x < pulsewidth) { //dec to 0
|
||||||
|
return (int16_t) (pulsewidth - x) * a / attdec;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put a value 0 to 255 in to get a color value.
|
* Put a value 0 to 255 in to get a color value.
|
||||||
* The colours are a transition r -> g -> b -> back to r
|
* The colours are a transition r -> g -> b -> back to r
|
||||||
@ -844,7 +870,7 @@ void WS2812FX::handle_palette(void)
|
|||||||
load_gradient_palette(paletteIndex -13);
|
load_gradient_palette(paletteIndex -13);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (singleSegmentMode && paletteFade) //only blend if just one segment uses FastLED mode
|
if (singleSegmentMode && paletteFade && SEGENV.call > 0) //only blend if just one segment uses FastLED mode
|
||||||
{
|
{
|
||||||
nblendPaletteTowardPalette(currentPalette, targetPalette, 48);
|
nblendPaletteTowardPalette(currentPalette, targetPalette, 48);
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user