I want to use Arduino Uno or a Nano which uses ATMEGA328P as micro-controller.
D2 is now set as INPUT. During the start up I want the MCU to detect whether pin D2 is HIGH or LOW depending on the setting set by the user. The setting will be done by an SPDT switch as shown below:
So if the switch pole is coupled to the +5V the state of D2 will be HIGH and if coupled to the GND the state will be LOW. Depending on this state in void main(), the program will perform a specific task.
I'm just not 100% sure whether it is very fine to connect pins that way. Is there any need for a pull-down resistor between the switch and the GND or between the switch and the +5V pin?
(What if the worst case D2 is accidentally set as OUTPUT pin?)