There is an issue with the previously shown fade mathematics which only appear on the Arduino. What seemed strange at first soon became clear. Micro-controllers are inherently more comfortable performing integer mathematics over floating point. After analysing the results of the equations which were output to the computer via serial, the issue became clear. Rounding error of floating point arithmetic. The reason behind this rounding error is a cumulative error build up by recalculating repeatedly with an already error vulnerable result.
A new method was created whereby this cumulative buildup was combated by tracking which iteration of a fade the system was currently on and using that to calculate the current value. Pretty simple really.
Step Size = ƒ
We have Xi and Xf ƒ = (Xf – Xi)/t
where t is fade time
Previously we were doing this:
Current Value =
We can see here that any previous rounding error gets re-included in this calculation.
Simple alternative method
Current Value = Xi + n . ƒ