Others will argue that common rail wiring is perfectly safe IF blah-blah is done. The IFs are where the risks enter into our high tech model railroads. The sketch below is a typical integration where the switch from the mainline automatically changes the yard power from the USC local cab to the mainline DCC when its moved into the reverse position. If you use insulated frog or other toy type switches, then you can use switch machine contacts to activate the relay. A 25msec period is possible 'with a minimum Off time of about 5 msec and 20 steps.
Options are yet to be explored.
Unused Pins are set as output.