How To Build a Flashlight With Perfect Modes (picture heavy)

You could use the STAR off time memory firmware as a code example. It reads ADC for the off time capacitor.
STAR Firmware by JonnyC