Button Matrix CD74HC4067 not working

Hi everybody,

i'm new to arduino and i try to build my own custom midi-controller for ableton live.
i've got a pus2-controller, but for effects and synths, i want to use custom-midi-controller.

Here is a picture:

I try to develope the code step by step, so i got the 4x4 button matrix working, if it's directly connected to 8 digital pins of my leonard.

Here the code:

Blockzitat
#include <Control_Surface.h>

USBMIDI_Interface midi;

// The note numbers corresponding to the buttons in the matrix

const AddressMatrix <4, 4> addresses {{
{36, 37, 38, 39},
{40, 41, 42, 43},
{44, 45, 46, 47},
{48, 49, 50, 51
},
}};

NoteButtonMatrix<4, 4> buttonmatrix {

{0, 1, 2, 3},
{4, 5, 6, 7}, // row pins
// column pins
addresses, // address matrix
CHANNEL_1, // channel and cable number
};

void setup() {
Control_Surface.begin();
}

void loop() {
Control_Surface.loop();
}

now i wanted to get the matrix running over 2 CD74HC4067, but it does nothing :frowning:

#include <Control_Surface.h>

USBMIDI_Interface midi;

CD74HC4067 mux1 = { 7, {2, 3, 4, 5} };
CD74HC4067 mux2 = { 8, {2, 3, 4, 5} };
// The note numbers corresponding to the buttons in the matrix

const AddressMatrix <4, 4> addresses {{
{36, 37, 38, 39},
{40, 41, 42, 43},
{44, 45, 46, 47},
{48, 49, 50, 51
},
}};

NoteButtonMatrix<4, 4> buttonmatrix {

{mux1.pin(0), mux1.pin(1), mux1.pin(2), mux1.pin(3)}, // row pins
{mux2.pin(0), mux2.pin(1), mux2.pin(2), mux2.pin(3)}, // column pins
addresses, // address matrix
CHANNEL_1, // channel and cable number
};

void setup() {
Control_Surface.begin();

mux1.begin();
mux2.begin();
//for(int i=0; i<15; i++);
// {
// //do I need to assign inputs and outputs?
mux1.pinMode(0, INPUT_PULLUP);
mux2.pinMode(0, INPUT_PULLUP);
// }
};

void loop() {
Control_Surface.loop();
}

i also can't get any action out of the buttons, if use just one multiplexer:

#include <Control_Surface.h>

USBMIDI_Interface midi;

CD74HC4067 mux_1{12, {8, 9, 10, 11} , }; //input, S0-S3, optional enable

// The note numbers corresponding to the buttons in the matrix

const AddressMatrix <4, 4> addresses {{
{36, 37, 38, 39},
{40, 41, 42, 43},
{44, 45, 46, 47},
{48, 49, 50, 51
},
}};

NoteButtonMatrix<4, 4> buttonmatrix {

{mux_1.pin(0), mux_1.pin(1), mux_1.pin(2), mux_1.pin(3)}, // column pins
{2, 3, 4, 5}, // row pins

 addresses,    // address matrix

CHANNEL_1, // channel and cable number
};

void setup()
{
mux_1.begin();

for(int i=0; i<3; i++)
{
//do I need to assign inputs and outputs?
mux_1.pinMode(i, INPUT_PULLUP);
}

Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
Control_Surface.loop();
}

could anybody help me?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

The CD74HC4067 class supports input only. The row pins of the button matrix are outputs. Scanning a matrix is simple enough though, you can write a version that supports multiplexers relatively easily, see e.g. Control Surface: ButtonMatrix.ipp Source File.

Ah okay :frowning:

So I can use the multiplexer only for Input(cols) and the Outputs have to be connected directly to the board?

Which board would you recommend for a diy-midi-controller?

I ordered a teensy 3.6 and a 4.2 board, because my leonardo seems to be a bit too slow for my project.
In the documentation only the teensy 3.2 is listed, but it's mentioned 4.x would also work?!

Thx for your answer

Andi

It's me again :slight_smile:

Instead of connecting the rows directly to the board, i could use a shift-register, right?

Thx a lot

Andi