You can connect the switch to either ground or Vcc (as long as the Vcc is the same as the one for your board). Connect a resistor to the other power rail (so the input has a defined state when the switch is off).
Or you configure the input pin as having a pull up (or pull-down resistor), then you can skip the external one.
1 of 1 people found this helpful
For examples: look at the IO pin component data sheet which is just a right-click away. Or do the right-click and then 'find code example'.