Based on Antonio Galea's soft_pwm, copied from https://github.com/tanzilli/soft_pwm/blob/daisy2