Adding code to PWM LED dimming

In my opinion you would be better off starting from scratch and writing your own program. It is often easier to do that rather than to untangle the logic of an existing program and try to add functionality to it and in addition you will learn a lot.

Do you have an RTC as assumed in the code in post #2 ?