Multiplexing for Midi Controller

Status
Not open for further replies.

Gripporillat

Well-known member
Hi everybody!

I'm trying to figure out how multiplexing works. If this is my circuit:

Test.jpg

and this is my code:

Code:
#include "MIDIcontroller.h"
byte MIDIchannel = 1;
const int Mpx1 = A0; //Multiplexer 1 on Pin A0
const int Mpx2 = 3; //Multiplexer 2 on Pin 3

MIDIpot PotMpx1Chan0(Mpx1, 0);     //Potentiometer on Multiplexer 1, Channel 0 for ControlChange #0
MIDIpot PotMpx1Chan1(Mpx1, 1);     //Potentiometer on Multiplexer 1, Channel 1 for ControlChange #1
MIDIpot PotMpx1Chan2(Mpx1, 2);     //Potentiometer on Multiplexer 1, Channel 2 for ControlChange #2
MIDIpot PotMpx1Chan3(Mpx1, 3);     //Potentiometer on Multiplexer 1, Channel 3 for ControlChange #3
MIDIpot PotMpx1Chan4(Mpx1, 4);     //Potentiometer on Multiplexer 1, Channel 4 for ControlChange #4
MIDIpot PotMpx1Chan5(Mpx1, 5);     //Potentiometer on Multiplexer 1, Channel 5 for ControlChange #5
MIDIpot PotMpx1Chan6(Mpx1, 6);     //Potentiometer on Multiplexer 1, Channel 6 for ControlChange #6
MIDIpot PotMpx1Chan7(Mpx1, 7);     //Potentiometer on Multiplexer 1, Channel 7 for ControlChange #7

MIDIbutton ButtonMpx2Chan0(Mpx2, 8, MOMENTARY);       // Button on Multiplexer 2, Channel 0 for ControlChange #8
MIDIbutton ButtonMpx2Chan1(Mpx2, 9, MOMENTARY);       // Button on Multiplexer 2, Channel 1 for ControlChange #9
MIDIbutton ButtonMpx2Chan2(Mpx2, 10, MOMENTARY);       // Button on Multiplexer 2, Channel 2 for ControlChange #10
MIDIbutton ButtonMpx2Chan3(Mpx2, 11, MOMENTARY);       // Button on Multiplexer 2, Channel 3 for ControlChange #11
MIDIbutton ButtonMpx2Chan4(Mpx2, 12, MOMENTARY);       // Button on Multiplexer 2, Channel 4 for ControlChange #12
MIDIbutton ButtonMpx2Chan5(Mpx2, 13, MOMENTARY);       // Button on Multiplexer 2, Channel 5 for ControlChange #13
MIDIbutton ButtonMpx2Chan6(Mpx2, 14, MOMENTARY);       // Button on Multiplexer 2, Channel 6 for ControlChange #14
MIDIbutton ButtonMpx2Chan7(Mpx2, 15, MOMENTARY);       // Button on Multiplexer 2, Channel 7 for ControlChange #15


void setup(){
}
void loop(){

    // select multiplexer channel 0
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 0
  PotMpx1Chan0.send();
  ButtonMpx2Chan0.send();

    // select multiplexer channel 1
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 1
  PotMpx1Chan1.send();
  ButtonMpx2Chan1.send();

    // select multiplexer channel 2
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 2
  PotMpx1Chan2.send();
  ButtonMpx2Chan2.send();

    // select multiplexer channel 3
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 3
  PotMpx1Chan3.send();
  ButtonMpx2Chan3.send();

    // select multiplexer channel 4
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 4
  PotMpx1Chan4.send();
  ButtonMpx2Chan4.send();

    // select multiplexer channel 5
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 5
  PotMpx1Chan5.send();
  ButtonMpx2Chan5.send();

    // select multiplexer channel 6 
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 6
  PotMpx1Chan6.send();
  ButtonMpx2Chan6.send();

    // select multiplexer channel 7
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);

  // check and send Values for all multiplexers channel 7
  PotMpx1Chan7.send();
  ButtonMpx2Chan7.send();

  
}

Is it gonna work?

I don't have those multiplexers available yet so I cant just try it.
Thx in advance!
Robert
 
Status
Not open for further replies.
Back
Top