Saturating Math, or how I learned to stop worrying and love 0xFF.

Saturating Math, or how I learned to stop worrying and love 0xFF.

Imagine if you could write this:

CRGB blueTint( 0, 20, 50);
...    
// now add some blue tint to an LED,
// add with saturation, i.e. no wrap-around past 255
leds[i] += blueTint; 

Well, now you can write exactly that. One of the new things the library has in V2 is a variety of “saturating” math functions. In LED programming (and DSP programming as well), using saturating math can save you lot of code, make your program easier to read, faster to write, and faster executing as well. There’s new page up with some more explanation as to what’s going on here:

Saturating Math… or how I learned to stop worrying and love 0xFF
https://code.google.com/p/fastspi/wiki/SaturatingMath