Nice job getting this sorted out. I like the presentation of your comments as well. +1
One thing I am not certain about is the correct way to handle the disconnected output in each of the two modes. I think that digitalWrite HIGH or LOW may be appropriate, but I don't really understand the circuit.