There's Pin as both input (for a switch) and output (for LED) with ATmega32U4? but I also need one of six such pins to drive a piezo buzzer. Due to its capacitive nature, I figured it could be connected to the GPIO as well (has no effect on DC signals):
simulate this circuit – Schematic created using CircuitLab
The idea was to suppress the noise, that would likely originate from switching the GPIO from output-low (to drive the LED) to input-pull-up (for sampling the pushbutton), using a high pass filter with an "odd" 1.5 kHz or so, so sampling at 100 Hz or so does not affect the 4 kHz piezo as much.
Drawbacks (both are acceptable):
- pushing the button lights the LED (and dumps C1's charge to ground; maybe add a series resistor?)
- driving the piezo with a 4 kHz square wave lights the LED at 50 % (maybe this can be a lower duty-cycle due to the filter?)
Does this work and can it be improved?