Added washing machine FX

pull/1208/head
S. Seegel 2020-09-27 01:58:21 +02:00
rodzic cac974b8e1
commit 2cc6edd868
2 zmienionych plików z 51 dodań i 3 usunięć

Wyświetl plik

@ -3712,3 +3712,48 @@ uint16_t WS2812FX::mode_dancing_shadows(void)
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.
By Stefan Seegel
*/
uint16_t WS2812FX::mode_washing_machine(void) {
int8_t speed= tristate_square8((uint16_t) (SEGMENT.speed + 100) * now / 20000, 90, 15) / 15;
SEGENV.step += speed;
for (int i=0; i<SEGLEN; i++) {
uint8_t col = sin8(((SEGMENT.intensity / 25 + 1) * 255 * i / SEGLEN) + SEGENV.step);
setPixelColor(i, color_from_palette(col, false, PALETTE_SOLID_WRAP, 3));
}
return FRAMETIME;
}

Wyświetl plik

@ -107,7 +107,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED )
#define MODE_COUNT 113
#define MODE_COUNT 114
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
@ -222,6 +222,7 @@
#define FX_MODE_FLOW 110
#define FX_MODE_CHUNCHUN 111
#define FX_MODE_DANCING_SHADOWS 112
#define FX_MODE_WASHING_MACHINE 113
class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void);
@ -426,6 +427,7 @@ class WS2812FX {
_mode[FX_MODE_FLOW] = &WS2812FX::mode_flow;
_mode[FX_MODE_CHUNCHUN] = &WS2812FX::mode_chunchun;
_mode[FX_MODE_DANCING_SHADOWS] = &WS2812FX::mode_dancing_shadows;
_mode[FX_MODE_WASHING_MACHINE] = &WS2812FX::mode_washing_machine;
_brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black);
@ -625,7 +627,8 @@ class WS2812FX {
mode_phased_noise(void),
mode_flow(void),
mode_chunchun(void),
mode_dancing_shadows(void);
mode_dancing_shadows(void),
mode_washing_machine(void);
private:
NeoPixelWrapper *bus;
@ -712,7 +715,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","Candle Multi", "Solid Glitter","Sunrise","Phased","Twinkleup","Noise Pal", "Sine","Phased Noise",
"Flow","Chunchun","Dancing Shadows"
"Flow","Chunchun","Dancing Shadows", "Washing machine"
])=====";