Hi, I'm trying to use two multiplexers (CD74HC4067) but I don't know how to make the code work. I'm specifically using the MIDI Control surface library with a Teensy 4.1 and two CD74HC4067's. My current sketch is copied from the MIDI Control Surface Library Page, which works fine with one multiplexer, but I don't know how to get two to work. I would like to have multiple analog inputs through one multiplexer to analog pin 0, and then a second set of analog inputs multiplexed to analog pin 1. My understanding is that I can use the same address pins for both multiplexers but I need to use separate input pins. The Teensy 4.1 has enough digital pins spare that I'm happy to use separate address pins if that would make it easier. Any help would be appreciated. This is my first project.
Thanks!
// Include the library
#include <Control_Surface.h>
// Instantiate a MIDI Interface to use
USBMIDI_Interface midi;
// Instantiate an analog multiplexer
CD74HC4067 mux {
A0, // Analog input pin
{0, 1, 2, 3} // 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), {MIDI_CC::Channel_Volume, Channel_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, Channel_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, Channel_3}},
{mux.pin(3), {MIDI_CC::Channel_Volume, Channel_4}},
{mux.pin(4), {MIDI_CC::Channel_Volume, Channel_5}},
{mux.pin(5), {MIDI_CC::Channel_Volume, Channel_6}},
{mux.pin(6), {MIDI_CC::Channel_Volume, Channel_7}},
{mux.pin(7), {MIDI_CC::Channel_Volume, Channel_8}},
{mux.pin(8), {MIDI_CC::Channel_Volume, Channel_9}},
{mux.pin(9), {MIDI_CC::Channel_Volume, Channel_10}},
{mux.pin(10), {MIDI_CC::Channel_Volume, Channel_11}},
{mux.pin(11), {MIDI_CC::Channel_Volume, Channel_12}},
{mux.pin(12), {MIDI_CC::Channel_Volume, Channel_13}},
{mux.pin(13), {MIDI_CC::Channel_Volume, Channel_14}},
{mux.pin(14), {MIDI_CC::Channel_Volume, Channel_15}},
{mux.pin(15), {MIDI_CC::Channel_Volume, Channel_16}},
};
// Initialize the Control Surface
void setup() {
Control_Surface.begin();
}
// Update the Control Surface
void loop() {
Control_Surface.loop();
}