What happens during reset when all the port pins are tristated? Since the arduino does not support pure atomic sequences in code you will have to disable the interrupts when switching. Look at this link it will give you some idea of what I am saying. Demonstration: Atomic access and Interrupt routines