Allow an analogue signal through unless a digital signal is present

there's various ways of doing this, but the simplest would probably be using an analog switch IC that you control with the digital input, which has two inputs, one of which you connect to your analog signal, the other which you simply tie to 5V.

In the more general case, "maximum of two inputs" is not hard; all you need would be two diodes:

schematic

simulate this circuit – Schematic created using CircuitLab

If your inputs are driven well enough and output is weakly, but pulled towards ground, a) is sufficient. I'd recommend you make sure that you neither put any large load on the diodes (as that will lead to an inequal voltage drop!), and make sure the output converges back to 0 V when the output becomes low, so go with something like b).

Now, you say:

I've got four button/fader pairs, and I want each one to be combined into one wire, with the digital signal overriding the analogue one.

well, that's even more trivial.

Your fader is probably a resistor, i.e. your analog signal has a relatively high source impedance.

That makes this really trivial:

schematic

simulate this circuit

The button pulls the output high, done!


An analogue multiplexer sounds like it could work. You can get them that are SPDT configuration and the control line chooses either (a) the analogue signal or (b) the digital signal. Maybe the ADG852 will do the job: -

enter image description here

Analogue sine wave going 0V to +5V is only input, output is the \$\color{red}{\boxed{\text{exact}}}\$ same sine wave

You'll never get an output that is "exactly" the same - there might be the odd 100 μV offset or 0.01% change in amplitude (depending on the source impedance of the sinewave and the loading of the output) but, it'll be "more secure" as a solution compared to diodes. If your sinewave frequency is above a few tens of MHz then there are other analogue multiplexers that are more intended for higher frequencies.


If you're not bothered about the small voltage drop, you could just use diodes to give you the maximum of the two voltages? Does require a fairly low impedance on the output though, as then the analogue input can't actively drive the output lower.

Other solutions might be available if we knew what the context was.