It might be good to explore what you need for automatically arming when falling down.
Depending on design of RC radio, when RC radio goes out of range it can simply stop sending servo pulses. The controller sees this and goes into "Failsafe mode". Failsafe mode can be set to do anything that can be done by a fixed set of stick and switch positions on the transmitter. The default for FC failsafe is to simply turn off all motors. This is the safest.
If for instance you want to just have Attitude mode with 40% throttle for your failsafe, you do not need to write code. It is already done. If you have GPS working you can have failsafe return to point of arming (called Base for Return To Base) and land and stop motors.
I suggest that you study / search / read about all this setup stuff first.