Pin as both input (for a switch) and output (for LED) with ATmega32U4?
Don't do this the way you describe. As I uderstand, your cicruit would look like:







simulate this circuit &ndash; Schematic created using CircuitLab

Now, assume the GPIO is in input mode (high impedance), and the button is not pressed. The voltage on the GPIO will be at about the LED forward voltage. Indeed, even though there will be very little current, there is a path through Rpullup-R2-D1, and there will be about 1.8V~2.5V (depending on the type of led you're using) at the MCU pin, which means logic level will be outside specs (it depends on the supply voltage you're using, but most likely, you'll be between high and low voltage limits). So the MCU won't behave consistently, and you won't really be able to tell if the button is pressed or not. The MCU may also consume excessive power in this case.

Here is what I came up with:







simulate this circuit

You must either drive the GPIO at low level to turn the led on, or set it to high impedance to turn the led off and eventually read the button state. The GPIO must never be actively driven high from the software, because if the button is pressed at the same time, the pin will be short-circuited.

The obvious drawback of the above circuit is that, when the button is pressed, the led will be fully on. But it seems not to be a problem in your case, and apart from this, this circuit is simple, safe for the MCU (if you follow the above rule) and guarantees correct input levels.