Glad you got the flickering issue resolved, that sucks about the breadboard.

I use the same formula for computing PWM steps, but simplified & rewritten as

range * 2 ^ ((x-domain) / 2)

yes, "^" means exponent.

Range is the bounds you want to cover, in this case it's 4095 because you want values from 0-4095.

Domain is one less than how many discrete steps you want to take to cover the range. For example say you want 20 levels of brightness, use 19 for the domain.

X=0, brightness = 0

X=1, brightness = 8

X=2, brightness = 11.31

...

X=18, brightness = 2895

X=19, brightness = 4095

Chris