Add after this line in setup:
// initialize switch pin (2) as an input:
pinMode(SwitchPin, INPUT);
digitalWrite (SwitchPin, HIGH); // enable internal pullup resistor - open switch will now go high
Add after this line in setup:
// initialize switch pin (2) as an input:
pinMode(SwitchPin, INPUT);
digitalWrite (SwitchPin, HIGH); // enable internal pullup resistor - open switch will now go high