Simplified police code

This commit is contained in:
cschwinne 2019-11-25 01:20:03 +01:00
parent 9e00177d76
commit 1d9d1f6bbd
2 changed files with 34 additions and 99 deletions

View File

@ -2346,95 +2346,36 @@ uint16_t WS2812FX::mode_static_pattern()
return FRAMETIME; return FRAMETIME;
} }
//American Police Light with all LEDs Red and Blue
uint16_t WS2812FX::mode_policeall()
{
SEGENV.step++;
if (SEGENV.step >= SEGLEN) {
SEGENV.step = 0;
}
uint16_t idexR = SEGENV.step;
uint16_t topindex = SEGLEN >> 1;
uint16_t idexB = idexR + topindex;
if (idexR >= topindex) idexB -= SEGLEN;
setPixelColor(idexR, RED);
setPixelColor(idexB, BLUE);
return SPEED_FORMULA_L;
}
//Police Lights Red and Blue //Police Lights Red and Blue
uint16_t WS2812FX::mode_police() uint16_t WS2812FX::mode_police()
{ {
fill(SEGCOLOR(1));
SEGENV.step += 1; return mode_policeall();
if (SEGENV.step >= SEGLEN) {
SEGENV.step = 0;
}
uint16_t idexR = SEGENV.step;
uint16_t topindex = SEGLEN / 2;
uint16_t antipodal;
antipodal = idexR + topindex;
if (idexR >= topindex) {
antipodal = (idexR + topindex) % SEGLEN;
}
uint16_t idexB = antipodal;
uint8_t thathue = (thishuepolice + 160) % 255;
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
if (i == idexR) {
CRGB newcolor = CHSV(thishuepolice, thissat, 255);
setPixelColor(idexR, newcolor.r, newcolor.g, newcolor.b, 0x00);
}
else if (i == idexB) {
CRGB newcolor = CHSV(thathue, thissat, 255);
setPixelColor(idexB, newcolor.r, newcolor.g, newcolor.b, 0x00);
}
else {
setPixelColor(i, 0, 0, 0, 0);
}
}
return SPEED_FORMULA_L;
} }
//American Police Light with all LED´s Red and Blue
uint16_t WS2812FX::mode_policeall()
{
SEGENV.step += 1;
if (SEGENV.step >= SEGLEN) {
SEGENV.step = 0;
}
uint16_t idexR = SEGENV.step;
uint16_t topindex = SEGLEN / 2;
uint16_t antipodal;
antipodal = idexR + topindex;
if (idexR >= topindex) {
antipodal = (idexR + topindex) % SEGLEN;
}
uint16_t idexB = antipodal;
uint8_t thathue = (thishuepolice + 160) % 255;
CRGB indexRCol = CHSV(thishuepolice, thissat, 255);
CRGB indexBCol = CHSV(thathue, thissat, 255);
setPixelColor(idexR, indexRCol.r, indexRCol.g, indexRCol.b, 0x00);
setPixelColor(idexB, indexBCol.r, indexBCol.g, indexBCol.b, 0x00);
return SPEED_FORMULA_L;
}
/*
* Lights every LED in a random color. Changes all LED at the same time
* to new random colors.
*/
uint16_t WS2812FX::mode_multi_dynamic()
{
for (uint16_t i = SEGMENT.start; i <= SEGMENT.stop; i++) {
setPixelColor(i, color_wheel(random8(SEGMENT.intensity)));
}
return (SEGMENT.speed);
}
//Speed slider sets number of "lights", intensity sets LEDs per light //Speed slider sets number of "lights", intensity sets LEDs per light
/*uint16_t WS2812FX::mode_static_pattern2() /*uint16_t WS2812FX::mode_static_pattern2()

View File

@ -84,7 +84,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED ) #define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )
#define MODE_COUNT 87 #define MODE_COUNT 86
#define FX_MODE_STATIC 0 #define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1 #define FX_MODE_BLINK 1
@ -173,7 +173,7 @@
#define FX_MODE_STATIC_PATTERN 83 #define FX_MODE_STATIC_PATTERN 83
#define FX_MODE_POLICE 84 #define FX_MODE_POLICE 84
#define FX_MODE_POLICE_ALL 85 #define FX_MODE_POLICE_ALL 85
#define FX_MODE_MULTI_DYNAMIC 86
class WS2812FX { class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void); typedef uint16_t (WS2812FX::*mode_ptr)(void);
@ -314,7 +314,6 @@ class WS2812FX {
_mode[FX_MODE_STATIC_PATTERN] = &WS2812FX::mode_static_pattern; _mode[FX_MODE_STATIC_PATTERN] = &WS2812FX::mode_static_pattern;
_mode[FX_MODE_POLICE] = &WS2812FX::mode_police; _mode[FX_MODE_POLICE] = &WS2812FX::mode_police;
_mode[FX_MODE_POLICE_ALL] = &WS2812FX::mode_policeall; _mode[FX_MODE_POLICE_ALL] = &WS2812FX::mode_policeall;
_mode[FX_MODE_MULTI_DYNAMIC] = &WS2812FX::mode_multi_dynamic;
_brightness = DEFAULT_BRIGHTNESS; _brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black); currentPalette = CRGBPalette16(CRGB::Black);
@ -493,8 +492,7 @@ class WS2812FX {
mode_halloween_eyes(void), mode_halloween_eyes(void),
mode_static_pattern(void), mode_static_pattern(void),
mode_police(void), mode_police(void),
mode_policeall(void), mode_policeall(void);
mode_multi_dynamic(void);
private: private:
NeoPixelWrapper *bus; NeoPixelWrapper *bus;
@ -527,10 +525,6 @@ class WS2812FX {
mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element
/*Define Variables for the Police Effects*/
int thissat = 255; //-FX LOOPS DELAY VAR
uint8_t thishuepolice = 0;
// mode helper functions // mode helper functions
uint16_t uint16_t
blink(uint32_t, uint32_t, bool strobe, bool), blink(uint32_t, uint32_t, bool strobe, bool),
@ -567,9 +561,9 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Running 2","Red & Blue","Stream", "Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Running 2","Red & Blue","Stream",
"Scanner","Lighthouse","Fireworks","Rain","Merry Christmas","Fire Flicker","Gradient","Loading","In Out","In In", "Scanner","Lighthouse","Fireworks","Rain","Merry Christmas","Fire Flicker","Gradient","Loading","In Out","In In",
"Out Out","Out In","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet", "Out Out","Out In","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet",
"Dual Scanner","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","BPM","Fill Noise", "Dual Scanner","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","Bpm","Fill Noise",
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Smooth Meteor","Railway","Ripple", "Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Smooth Meteor","Railway","Ripple",
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Police","Police All","Multi Dynamic" "Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Police","Police All"
])====="; ])=====";