I understand how pullup and pulldown resistors work with push buttons and I also understand that an analogous idea can be applied to slide switches. Furthermore, I know that some versions of Arduino have an internal pullup resistor that can be used, if you adjust the code properly.
I was wondering, if I can, without using the internal pullup resistor, wire a slide switch without any kind of resistor like so:
As I understand, this should behave exactly the same as using a pull-down resistor. If the switch is on the left side, pin 7 would read LOW
and if the switch is on the right side, it would read HIGH
.
Is that a problem with wiring the switch like this? Is there a reason why using a resistor would be better?
In my final project I intend to use a Digispark board and I would not like to rely on its internal resistor and I also would like to avoid using an external resistor if I can.
pinMode(pin, INPUT_PULLUP)
instead ofpinMode(pin, INPUT)
. And a real life switch might have a short time where nothing connected during thr switching action. For handling that you might need to increase the debounce time with your setup.