hello! i'm a complete beginner with arduino (and with programming in general) and like many before me i'm trying to build a custom MIDI-controller. i'm having trouble with jittery/noisy/unwanted output from my potentiometers, and i know this is a common issue for beginners but all the posts i could find were based on the old library MIDI_controller and i wonder if there are simpler ways of dealing with this in control_surface. apologies if i've missed an old thread that addresses my specific problem!
so, the problem is: when i connect my potentiometers directly to the arduino they work fine, but if i try to multiplex them they start outputting a continuous stream of values and they don't respond linearly, so it's basically impossible to use them. i'm on an arduino leonardo and i'm just trying to implement a simple prototype that i would want to scale up at a later point (because my goal is to have a midi controller with up to 96 elements between potentiometers and buttons, using 16-channel multiplexers). i took the code on this page and tweaked it to begin making a first prototype. here's the result:
// Include the library
#include <Control_Surface.h>
// Instantiate a MIDI Interface to use
USBMIDI_Interface midi;
// Instantiate an analog multiplexer
CD74HC4051 mux {
A0, // Analog input pin
{0, 1, 2} // Address pins S0, S1, S2
};
// Create an array of potentiometers that send out
// MIDI Control Change messages when you turn the
// potentiometers connected to the eight input pins of
// the multiplexer
CCPotentiometer volumePotentiometers[] {
{ mux.pin(0), {10, CHANNEL_1 } },
{ mux.pin(1), {20, CHANNEL_1 } },
{ mux.pin(2), {30, CHANNEL_1 } },
{ mux.pin(3), {40, CHANNEL_1 } },
};
CCPotentiometer potentiometer_01 { A5, {17, CHANNEL_1} };
// Initialize the Control Surface
void setup() {
Control_Surface.begin();
}
// Update the Control Surface
void loop() {
Control_Surface.loop();
}
i'm working on a small bread board and i can only fit 4 potentiometers onto it. while testing my prototype, i unplugged one of them and connected it to A5 and it worked perfectly. only the potentiometers connected to the multiplexer behave erratically. i tried the same thing with a 4-bit multiplexer and had exactly the same issue. i swapped the potentiometers for buttons (and adapted the code for this configuration) and the buttons worked fine.
the potentiometers are 10k, i tried to power them separately from the multiplexer through leonardo's 3.3v outlet but it didn't change a thing.
any help would be greatly appreciated
(p.s. i understand that using hysteresis should help with this issue as the values outputted are all within a relatively small range but i couldn't figure out how to implement that from reading control_surface's documentation and i kind of gathered from an old post by the library's author that it should work automatically if i scratch my head a bit more i can soon start a career as a brain surgeon!)