So a few months ago I scavenged some footswitches from the secret electrical engineering department free stuff room. I didn't really have a plan for them, so I terminated them with 1/4" plugs forgot about them.
Then the other day I read about some software that MOTU is coming out with called Volta. It converts digital (MIDI, etc) control signals to analog control voltage for interfacing computers with analog synth gear. The cool, elegant part about it is that it does this by using your existing hardware. If you have a multichannel audio interface, which MOTU just happens to sell, the audio outputs become general voltage outputs using Volta.
This got me thinking that it would be pretty easy to do the opposite: I could use the inputs on my (coincidentally MOTU-brand) audio interface to hook up a footswitch to my (Windows) computer. Since the switch is just a passive momentary switch (short circuit when pressed down, open otherwise) I would need a voltage source in series with the switch to provide a signal that could be detected by the sound card. Most audio interfaces have a DC-blocking highpass filter on the input to protect it from stupidity-based damage. Because of this filtering, the digital signal doesn't look how one might expect. A back-of-the-envelope sketch illustrates:
The first step was to install a battery inside the footswitch. Since there would be virtually no current drawn from the battery, I elected to install the battery in a moderately permanent fashion, soldering wires directly to the terminals and hot gluing the battery in place. Note to potential future employers: this is not representative of my overall regard for safety, it's just a weekend project and I didn't have any battery clips around.
I reattached the top half of the case and plugged it into one of the line inputs on my sound card. I tested it out and it worked exactly as expected. Note that I installed the battery backwards so the 'on' pulse is negative instead of positive:
With the hardware side finished, I had to decide the best way to control music software with the footswitch. I settled upon converting it to a MIDI note event. I installed Maple Virtual Midi Cable, a tiny piece of software for Windows which provides virtual MIDI ports for sending data between programs. Then, I built up a patch in PD to convert the positive and negative pulses to MIDI. This was my first foray into PD, so I'm sure there's some trivial way to implement this that I didn't know about.
And that's it. As I implemented it, it takes the input from the third channel of the sound card and outputs a MIDI note on when the switch is depressed and a note off when it's released. Note that a velocity of zero is the same as a note off message. This patch could be easily parallelized by duplicating it and changing the ADC channel and MIDI note numbers.
The only downside to this simple method is that you can't generalize it to continuous controllers like a knob or expression pedal. You would need to send an AC signal through the controller since the highpass filter doesn't allow you to see small or slow variations in level, just impulses or quick steps. So I'll leave that modification for another day.