One simple way, use ATTINY85 to do supply sensing and PWM generation.
Here is a block programed partial solution that does both ramps. Note it can
easily be modified to handle a brownout type situation if you care about that.
mBlock takes the blocks you config and generates the Arduino code for you.
Current functionality is on power on a ramp up is done. Then if ATTINY85 detects
10 V from a 1/4 voltage divider external then a ramp down is performed.
Solution then stays in do nothing loop until power is lost and ATTINY85 restarts.
You can change the 10V to whatever you consider loss of power V should be.
Design should power up with no funky artifacts as ATTINY85 power up is well
controlled internally. I would add a 10K R from Darlington base to ground to
absorb leakage when Darlington is supposed to be off. For startup considerations
when ATTINY85 I/O pin is in no mans land for first couple of volts. and then it starts up
as input until program takes over and forces it as output logic 0. Note if you used
a logic level MOSFET with a threshold around 3 - 4 V that would be better to insure
no false turn on occurs.
You would need a nano or uno board to program the ATTINY85, and ATTINY85, a bypass cap
for it, 2 R;s to do a 1/4 V divider for power sensing, and the power interface to LED string, eg.
the Darlington. Timing accuracy much better that 555 timer, including T and V effects.
The ATTINY85 would need a 3 term TO92 V regulator, as that acts also as Vref for A/D in this example.
A 2% part would be a better Vref than its onboard Vref. or a shunt zener with tight tolerance for a
regulator.
ATtiny Programmer Shield Arduino Nano Materials, Connect the components and wires as shown in the two post pictures and configuration.
Project attached. Use mBlock 5.3.5 to open.
Regards, Dana.