When I power off my strips,

When I power off my strips, I often see random color sparkles for a second or so. I’m guessing that has to do with the “safety” capacitor I use to remove any spikes when switching power on. Can anyone think of a method for the arduino to detect that it is being switched off and then have enough time to set all LEDs to black? Or any other method for that matter?

A push button that ends the sketch and turns everything to black. Then cut the power.