Update on Nov 30, 2025: This Gist is nearly eight years old! These instructions worked back in 2018 for the Pi 3, but recent comments suggest that they may not be sufficient on more recent Pi models and newer versions of Raspberry Pi OS. Be advised.
On my RetroPie machine I wanted a hardware volume knob — the games I play use a handful of emulators, and there's no unified software interface for controlling the volume. The speakers I got for my cabinet are great, but don't have their own hardware volume knob. So with a bunch of googling and trial and error, I figured out what I need to pull this off: a rotary encoder and a daemon that listens for the signals it sends.