Fade PWM in (almost) realtime.

I have a clock setup that is changing LED brightness according to the last number in the seconds value. this number can be 0 to 5. So to get the PWM i have done this...

TimeInPWM = map (TimeFromRTC, 0, 5, 0, 255);

This gives me a LED that brightness can tell you the value of the ones digit that represents the current second.

I am trying to find a way to have the led fade from one value to another instead of have it jump exactly on the second tick. Any thought on how i can accomplish this ?

Presumably you know how long it takes for the last number in the seconds value to increment by one, so can't you just ramp up the brightness at the appropriate speed based on elapsed time?

I can use a For loop, but i run the danger of the loop taking longer to complete than the clock takes to cycle if i only increment by one. I could do larger increments but loose resolution.

modemover:
I can use a For loop, but i run the danger of the loop taking longer to complete than the clock takes to cycle if i only increment by one. I could do larger increments but loose resolution.

Decide how many steps you want to have i.e. how smoothly you want the change to occur and then work out how long an interval you need between each step, and then alter the value by one step at that interval.