Problems tracking pin state with Switch statement