I didn't really study your code but one thing that can foul-up PWM is to analogWrite() every millisecond or so, every time through the loop.
PWM is "set and forget" so you should only re-write when you want to change it.
I didn't really study your code but one thing that can foul-up PWM is to analogWrite() every millisecond or so, every time through the loop.
PWM is "set and forget" so you should only re-write when you want to change it.