So If the switch is not pressed, the input pin is floating, unless there are weak pull-ups in play here. If not, try adding a pull-up to the input. This way the input is either high or low, but never allowed to float.