From 04362e9fb3ff57f19b8e50ebb893d1db60d8094e Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 9 Jan 2018 19:04:19 +0100 Subject: [PATCH] add circle mapping and radar effect --- NeoPatterns.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++ NeoPatterns.h | 47 ++++++++++++++++++++++++++- esp-videoswitcher.ino | 3 ++ 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/NeoPatterns.cpp b/NeoPatterns.cpp index a209704..b45fb86 100644 --- a/NeoPatterns.cpp +++ b/NeoPatterns.cpp @@ -48,6 +48,9 @@ void NeoPatterns::Update() { case PLASMA: PlasmaUpdate(); break; + case RADAR: + RadarUpdate(); + break; case FILL: break; case RANDOM: @@ -480,6 +483,67 @@ void NeoPatterns::PlasmaUpdate() } +void NeoPatterns::Radar(float radarspeed,float radarthickness, uint8_t interval) +{ + ActivePattern = RADAR; + Radarspeed = radarspeed; + Interval = interval; //interval time in ms + Radarposition=0; + Radarthickness=radarthickness; + Radarfadelength=8; + Radardotposition=10; + Radardotbrightness=0; + Radardotfadespeed=10; +} + +void NeoPatterns::RadarUpdate() +{ + Radarposition += Radarspeed; + while (Radarposition>=32){ + Radarposition-=32; + } + while (Radarposition<=-32){ + Radarposition+=32; + } + + for (int i=0;i<32;i++){ + uint32_t c= Color(0,0,0); + + float angulardistance; + if (Radarspeed>0){ + angulardistance=Radarposition-i; + if (angulardistance<0){ + angulardistance+=32; + } + + } + + + if (angulardistance<=Radarfadelength){ + uint8_t _brightness=(Radarfadelength-angulardistance)*255/Radarfadelength; + + c= Color (int( pow( (_brightness/255.0),2)*255.0), _brightness ,int(pow( (_brightness/255.0),2)*200.0) ); + } + + colorCircleSegment(i, c); + } + if (abs(Radarposition-Radardotposition)<=1){ + Radardotbrightness=255; + } + if (Radardotbrightness>10){ + Radardotbrightness-=Radardotfadespeed; + colorCircleSegment(Radardotposition, Color (Radardotbrightness,0,0)); + }else{ + if (random(100)==0){ + Radardotposition=random(0,32); //set new position + } + } + + + show(); +} + + /****************** Helper functions ******************/ void NeoPatterns::SetColor1(uint32_t color) { @@ -519,6 +583,8 @@ void NeoPatterns::colorBox(uint8_t boxid, uint32_t c){ //color a box } + + void NeoPatterns::setupboxs() { boxs[1].left = 55; boxs[1].middle = 56; @@ -622,6 +688,14 @@ void NeoPatterns::setupboxs() { boxs[0].right = 39; } +void NeoPatterns::colorCircleSegment(uint8_t wheelid, uint32_t c){ //color a wheel segment + for (int i=0;i<4;i++) { + setPixelColor(boxcircle[wheelid][i], c); + } + show(); +} + + void NeoPatterns::ColorSetParameters(String parameters) diff --git a/NeoPatterns.h b/NeoPatterns.h index 7725727..b902f17 100644 --- a/NeoPatterns.h +++ b/NeoPatterns.h @@ -1,7 +1,7 @@ #include // Pattern types supported: -enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, FILL, RANDOM }; +enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, RADAR, FILL, RANDOM }; // Patern directions supported: enum direction { FORWARD, REVERSE }; @@ -34,6 +34,8 @@ class NeoPatterns : public Adafruit_NeoPixel void SmoothUpdate(); void Plasma(float phase = 0, float phaseIncrement = 0.08, float colorStretch = 0.11, uint8_t interval = 60); // 0.08 and 0.11 // 0.03 und 0.3 void PlasmaUpdate(); + void Radar(float radarspeed = 1,float radarthickness = 1, uint8_t interval = 50); + void RadarUpdate(); void SetColor1(uint32_t color); void SetColor2(uint32_t color); @@ -48,9 +50,44 @@ class NeoPatterns : public Adafruit_NeoPixel }; struct box boxs[25]; + uint8_t boxcircle[32][4]={ + {0,0,0,0}, //0 + {1,2,2,2}, + {3,4,4,4}, + {5,6,7,8}, //3 + {9,10,11,11}, + {12,13,13,13}, //5 + {14,14,14,14}, + {255,255,255,255}, + {15,16,17,17}, + {255,255,255,255}, + {18,19,20,29}, //10 + {22,23,27,28}, + {21,25,26,30}, + {24,31,32,33}, //13 + {34,34,34,34}, + {255,255,255,255}, //15 + {255,255,255,255}, //16 + {39,39,39,39}, + {36,37,38,45}, + {35,43,44,48}, //19 + {41,42,46,47}, + {40,49,50,51}, + {255,255,255,255}, //22 + {52,53,54,54}, + {255,255,255,255}, + {55,55,55,55}, + {56,57,57,57}, + {58,59,60,60}, //27 + {61,62,63,64}, + {65,66,66,66}, + {67,68,68,68}, + {69,69,69,69} //31 + }; void setupboxs(); void colorBox(uint8_t boxid, uint32_t c); + void colorCircleSegment(uint8_t segmentid, uint32_t c); void ColorSetParameters(String parameters); uint8_t Red(uint32_t color); uint8_t Green(uint32_t color); @@ -103,6 +140,14 @@ class NeoPatterns : public Adafruit_NeoPixel float SavedPlasmaPhaseIncrement; float PlasmaColorStretch; float SavedPlasmaColorStretch; + + float Radarposition; + float Radarspeed; + float Radarthickness; + float Radarfadelength; + float Radardotposition; + uint8_t Radardotbrightness; + uint8_t Radardotfadespeed; uint32_t DimColor(uint32_t color); diff --git a/esp-videoswitcher.ino b/esp-videoswitcher.ino index 4a7519c..4aa88e7 100644 --- a/esp-videoswitcher.ino +++ b/esp-videoswitcher.ino @@ -193,6 +193,9 @@ bool onSetEffect(const HomieRange& range, const String& value) { else if (effect == "plasma") { strip.Plasma(); } + else if (effect == "radar") { + strip.Radar(); + } else { // Test whether command with parameters was sent int sep = value.indexOf("|");