LDR with 7 seg display and PWM output

Doesn't work properly.

What does it do that is wrong ? Does it work predictably if you set the value variable to a fixed number rather than calculating it ? Have you tried printing the value variable and if so what range of values do you get ? How is the LDR wired ?