From 84b7bfb989e662e37a47d78e381105b3951311a6 Mon Sep 17 00:00:00 2001 From: pjhatch <66844564+pjhatch@users.noreply.github.com> Date: Sun, 28 Jun 2020 19:59:46 -0500 Subject: [PATCH] update for lost balls Added some protection - so that when intensity is lowered and raised some time later balls that have moved way off the track are recovered. --- wled00/FX.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index d57854a8..cb9d3f3f 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2635,8 +2635,13 @@ uint16_t WS2812FX::mode_balltrack(void) { balls[i].mass=(float(random16(5000, 10000)) / 10000.0); // from .5 to 1. } + float timeSinceLastUpdate = (time - balls[i].lastBounceUpdate)/((255-SEGMENT.speed)*8/256 +1); //uses Air Cookie conversion balls[i].height += balls[i].velocity * timeSinceLastUpdate/1000/10; + // test if intensity level was increased and some balls are way off the track + if(balls[i].height<-.5 || balls[i].height> 1.5){ + balls[i].height=(float(random16(0, 10000)) / 10000.0); // from 0. to 1. + } if (balls[i].height < 0. && balls[i].velocity<0) balls[i].velocity=-balls[i].velocity; //reverse velocity if (balls[i].height > 1. && balls[i].velocity>0) balls[i].velocity=-balls[i].velocity; // reverse velocity