I think the code is producing a linear change in PWM duty cycle. What you're perceiving as being non-linearity is probably a result of the fact that LED (and most lamps in general) brightness do not change linearly with a change in voltage.
You should actually be trying to create a logarithmic rate of change in order to produce a linear change of brightness
Bookmarks