tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
402 stars 70 forks source link

MIDI_Controller Issue With 74HC4067 multiplexer #29

Closed BBABO closed 6 years ago

BBABO commented 6 years ago

Hi, First of all thank a lot for your awesome workc ! I've started midi controller building with a teensy 3.2 thank's to MIDIUSB library then i wanted to go for an Arduino Mega 16u2 in order to have more I/O.

I'd rapidly realised that's arduino Mega wasn't natively able to comunicate Midi over usb but thank's to your work and your extremely well explained guide i managed to flash the arduino mega and do some basic stuff with your MIDI controller Library.

The problem occurred when i tried to use 74HC4067 16 channel multipkexer with the Midi controller library. I used this library to Read the multiplexer : Everything is okay with reading the multiplexer , ( i've had a problem with the multiplexer reading false value, to solve this i've had to connect unused multiplexer pin to ground ) but when i try this the potentiometer work fine but it's sending on all CC 1 to 15. So despite the potentiometer is intend to send is value on CC 1 it is sending on all CC 1 to 15 .

I dont know where is the error, i'm new into arduino so i hope i didn't make a beginer fault. Thank's again for your work 👍 Full support From France !

Here is the complete code :

#include <MUX74HC4067.h>
#include <MIDI_Controller.h>

// Setting up the multiplexer with EN,S0,S1,S2,S3 PIN
MUX74HC4067 mux1(35, 47, 46, 45, 44);

//Here i'm creating 2 array that store the value of each potentiometer connected to the 0-15 input of the Multiplexer
//M1 array is for the "old" value and nM1 array is for "freshly readed value"
int M1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int nM1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

//here i'm trying to initialize 16 potentiometer element That's send value from the M1 array via CC 1 to 16 on channel 1 (maybe the error is here but i dont know an other way to do this)
Analog M1pot[] = {
  {M1[0], 1, 1},
  {M1[1], 2, 1},
  {M1[2], 3, 1},
  {M1[3], 4, 1},
  {M1[4], 5, 1},
  {M1[5], 6, 1},
  {M1[6], 7, 1},
  {M1[7], 8, 1},
  {M1[8], 9, 1},
  {M1[9], 10, 1},
  {M1[10], 11, 1},
  {M1[11], 12, 1},
  {M1[12], 13, 1},
  {M1[13], 14, 1},
  {M1[14], 15, 1},
  {M1[15], 16, 1},
};

void setup() {
  // Mux Setup : here i'm telling that the multiplexer is used as analog input connected on A0
  mux1.signalPin(A0, INPUT, ANALOG);
}

void loop() {
  // Mux Read
  for (int i = 0; i < 16; ++i) { //here i compare the new value readed with the old one and if it's different i replace the old one
    nM1[i] = mux1.read(i);
    if (abs( nM1[i] - M1[i] ) > 4 ) {
      M1[i] = nM1[i];
    }
  }
  MIDI_Controller.refresh();
}
tttapa commented 6 years ago

The first argument of the Analog constructor is a pin number, not a value.

The library supports multiplexers right out of the box, you can use:

AnalogMultiplex multiplexer(A0, { 47, 46, 45, 44 } ); // 74HC4067

Analog potentiometers[] = {
  {multiplexer.pin(0), 0x1, 1},
  {multiplexer.pin(1), 0x2, 1},
  {multiplexer.pin(2), 0x3, 1},
  {multiplexer.pin(3), 0x4, 1},
  {multiplexer.pin(4), 0x5, 1},
  {multiplexer.pin(5), 0x6, 1},
  {multiplexer.pin(6), 0x7, 1},
  {multiplexer.pin(7), 0x8, 1},
  {multiplexer.pin(8), 0x9, 1},
  {multiplexer.pin(9), 0xA, 1},
  {multiplexer.pin(10), 0xB, 1},
  {multiplexer.pin(11), 0xC, 1},
  {multiplexer.pin(12), 0xD, 1},
  {multiplexer.pin(13), 0xE, 1},
  {multiplexer.pin(14), 0xF, 1},
  {multiplexer.pin(15), 0x10, 1}
};

You don't need #include <MUX74HC4067.h> at all.

BBABO commented 6 years ago

Thank's a lot for the rapid answer ! So cool that the multiplexer is already included in the library ! 🥇 I tought it was only for 8 channel multiplexer ! Thank again ! Can i make a donation for support ?