I'm using the [amazing!] Control Surface library.
I can't figure out for the life of me how to wire my CD74HC4067 multiplexer. My goal is to create an 8x8 matrixed 61-note MIDI controller. My code is below. I have the 8x8 matrix wired up and ready to go - diodes and all (it's a pretty standard keyboard matrix). I intend to feed 8 columns and 8 rows into the multiplexer, but I don't have any idea how to wire the multiplexer to my Arduino Mega in the first place.
#include <Control_Surface.h> // Include the Control Surface library
#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
HairlessMIDI_Interface midi;
using namespace MIDI_Notes;
// Instantiate a multiplexer
CD74HC4067 mux_I{2, {3, 4, 5, 6} , }; //input, S0-S3, optional enable
const AddressMatrix<8, 8> addresses
{{
{36, 37, 38, 39, 40, 41, 42, 43},
{44, 45, 46, 47, 48, 49, 50, 51},
{52, 53, 54, 55, 56, 57, 58, 59},
{60, 61, 62, 63, 64, 65, 66, 67},
{68, 69, 70, 71, 72, 73, 74, 75},
{76, 77, 78, 79, 80, 81, 82, 83},
{84, 85, 86, 87, 88, 89, 90, 91},
{92, 93, 94, 95, 96, 97, 98, 99},
}};
NoteButtonMatrix<8, 8> matrix_I
{
{
mux_I.pin(8), mux_I.pin(9), mux_I.pin(10), mux_I.pin(11), // row pins
mux_I.pin(12), mux_I.pin(13), mux_I.pin(14), mux_I.pin(15)
},
{
mux_I.pin(0), mux_I.pin(1), mux_I.pin(2), mux_I.pin(3), // column pins
mux_I.pin(4), mux_I.pin(5), mux_I.pin(6), mux_I.pin(7)
},
addresses, // address matrix
CHANNEL_1, // channel and cable number
};
void setup()
{
mux_I.begin();
/*for (int i=0; i<8; i++) //not sure if I need this
{
mux_I.pinMode(i, OUTPUT);
mux_I.pinMode(i+8, INPUT);
}*/
pinMode(3, INPUT_PULLUP);
Control_Surface.begin(); // Initialize Control Surface
}
void loop()
{
Control_Surface.loop(); // Update the Control Surface
}
//Thanks to PieterP's example code
Thanks in advance for any guidance!