PWM Programming Help

int ledPin = 2;    // LED connected to digital pin 2

Pin 2 is not a PWM pin. Only 3, 5, 6, 9, 10, and 11 on the UNO. There is a little '~' next to the PWM pins on the board.

If you use analogWrite() on a non-PWM pin you get LOW for values below 512 and HIGH for higher values.