The current value 0 can lead to hang up.
Btw, you do not need to set the mode for PWM pins, it is set in the core when calling analogWrite() (see here).
Or, as a faster alternative, you could set only once the pin mode to PWM in setup and then use
Code: Select all
pwmWrite(pin, duty_cycle8 * 257)
Code: Select all
analogWrite(pin, duty_cycle8).