Using RgbColor::Compare to detect end point for color blending fade. #814
-
I'm building a small, multi-strip controller based on the atmega328p (arduino uno if it was still an uno). The NeoPixelBus library has made things simple but I like to do most things "the hard way" because I'm stupid. So instead of using animations, I wanted to make my own "fade between color" routine. I'm fighting with RgbColor::Compare to determine when my updates have reached the end state. quick notes:
Here is my code:
My assumption is that I'm using the RgbColor::Compare incorrectly (or missing somthing obvious). I could not see any use of RgbColor::Compare in the examples. Thank you in advance for any hints. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
https://github.com/Makuna/NeoPixelBus/wiki/RgbColor-object-API#static-int16_t-compareconst-rgbcolor-left-const-rgbcolor-right-uint8_t-epsilon--1 I think your iterative approach isn't a good one. Think time, how long do you want your blend action to take, from one color to another color. The LinearBlend can take either 0-255 or 0.0 -1.0 for progress. Iterate on this progress value from the original color to the new color, and not rely on comparing to end the loop. Then change the time based on the steps you take for progress and the delay you use in the loop. This is the technique used in the animation examples, look at the animation callback. All the animation system really does is manage the time and this progress value as a float (0.0-1.0) for multiple "animations" so reduce code that you would need to implement. |
Beta Was this translation helpful? Give feedback.
https://github.com/Makuna/NeoPixelBus/wiki/RgbColor-object-API#static-int16_t-compareconst-rgbcolor-left-const-rgbcolor-right-uint8_t-epsilon--1
Epsilon is how sloppy you want the compare to be. You provided 200! Usually, 1, the default is good. Sometimes depending on how you are blending, you might go as high 6. But anything over 25 you may need to rethink your approach.
I think your iterative approach isn't a good one. Think time, how long do you want your blend action to take, from one color to another color. The LinearBlend can take either 0-255 or 0.0 -1.0 for progress. Iterate on this progress value from the original color to the new color, and not rely on comparing to end the loop.…