I want to make a sketch which behaves differently, i.e.:
pinMode(pin1, OUTPUT);
digitalWrite(pin1, HIGH);
pinMode(pin2, OUTPUT);
digitalWrite(pin2, LOW);
pinMode(pin3, INPUT);
// And a user decides to short pin3 with pin1 or pin2
if (digitalRead(pin3) == HIGH) {
// behavior 1
} else {
// behavior 2
}
But, I wonder whether shorting two pins with/without a resistor safe or not. If it is dangerous, what is an alternative way to do such a thing?
pinMode(pin3, INPUT_PULLUP);, this way you condition the sketch on the pin being either grounded or not. You can then connect a switch between pin 3 and GND to have the switch control the behavior. – Edgar Bonet Aug 10 '17 at 14:55