analogue input to volume control

flok

Well-known member
Hi,

I created a piece of plastic with a potentiometer and a Teensy 4.0 in it.
The idea was that with the knob I could adjust the soundvolume of my Linux-system.
I thought I could do so with keyboard-events. Had I researched better (but yeah) I would've known that it would only work with an encoder-type dial.
Or am I wrong? Teensy uC has quite a few USB-types it can pretend to be, would an other mode allow me to do this?
I can also of course write a program for the Teensy that sends the measured values as a byte-stream and then capture that at the Linux-side and adjust the soundvolume by that, but that is not be easy portable to other systems.
So: any ideas?

1789742115342.png
1789742235780.png
 
C-like:
void loop ()
{
    if (current != previous)
    {
        #if absolute
        sendMessage(current);
        #endif

        #if relative
        sendMessage(current - previous);
        #endif

        previous = current;
    }
}
Of course, you'll need some input filtering and possibly some hysteresis to avoid a stream of messages because of noise, but that's the basic idea.

If you need to send a series of fixed-size steps, then you might inc/dec a counter for each step until it matches the pot. Only a match is quiet.
But it has no way to know that something else has changed the system volume, so it could easily be way off. Easily fixed though, by turning the knob all the way to the stop, in the direction that makes the host hit that limit first, and then you're matched again...if you even need that match. If a quick relative adjustment is all you need and you still have enough travel to do it, then that works, right?

Also consider startup, if the pot is somewhere other than where previous initializes to...

Or, as a frame challenge, is there a reason this can't be a literal analog audio pot?
 
Last edited:
Back
Top