Simply connect the led + series resistor between 5V and the Arduino pin. Place the button between the Arduino pin and ground. When the button is pressed, current will flow and the led will light, and the Arduino pin will be pulled to ground. When the button is not pressed, the Arduino pin will be pulled to 5V. A very very tiny current will flow into the Arduino pin, not enough to light the led.If you want the led to extinguish when the button is pressed, use a push-to-break button.This seems so simple, I am wondering if I understood your question.
thanks. what about for a momentary switch?
This seems so simple, I am wondering if I understood your question.
I would like to read a switch on an I/O pin, and have an LED illuminate or extinguish when the switch is pressed.
Assuming a latching switch, what are the advantages/disadvantages of doing it the way you have suggested, compared to tieing the port to ground with 10k. A switch from 5v to the port. and a LED with series resistor from port to ground?
For a LED and switch to be used on the same pin see wiring: