Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: conflict in 2 mux16 code

  1. #1

    conflict in 2 mux16 code

    hello to all
    i m working on a project with 2 mux16 (74HC4067) connected to teensy3.6 all channel of the mux16 connected to buttons accept the last one
    so i got 31 buttons im using this code t send sysex masseges when i press some button.
    all the buttons r working great accept mux(1) channel 10.
    first my guess was the soldering connection but i checked and do some measurement for all connections and everything is ok.
    so i go to the code and i try to remove everything that related to mux(2) and finaly ch10 in mux(1) starts responding but then ch3 in mux(1) not respond.
    hope u guys can help me with this code conflict.
    here is the code im using:
    Code:
    #include <Bounce.h>
    const int channel = 1;
    
    // Store the elapsed milliseconds for analog and multiplexed input smoothing/de-bouncing
    elapsedMillis msec1 = 0;
    long msecMux1[5] = {0, 0, 0, 0, 0};
    
    elapsedMillis msec2 = 0;
    long msecMux2[5] = {0, 0, 0, 0, 0};
    
    // Setup mux1 chip pins
    const int selectPins1[4] = {43, 44, 45, 46}; // S0~0, S1~1, S2~12
    const int zInput1 = 13; // Connect common (Z) to 19 (digital input)
    
    // Setup mux2 chip pins
    const int selectPins2[4] = {24, 25, 26, 27}; // S0~0, S1~1, S2~12
    const int zInput2 = 28; // Connect common (Z) to 19 (digital input)
    
    
    
    // Mux1 button states for de-bouncing
    int buttonState1[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    int buttonStatePrev1[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    
    
    // Mux2 button states for de-bouncing
    int buttonState2[15] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,};
    int buttonStatePrev2[15] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,};
    
    void setup() {
    
      // Set up the select pins as outputs for the mux chip and raise them:
      for (int i = 0; i < 16; i++)
      {
        pinMode(selectPins1[i], OUTPUT);
        digitalWrite(selectPins1[i], HIGH);
    
        pinMode(selectPins2[i], OUTPUT);
        digitalWrite(selectPins2[i], HIGH);
      }
      // Set up mux Z as an input
      pinMode(zInput1, INPUT_PULLUP);
    
      // Set up mux Z as an input
      pinMode(zInput2, INPUT_PULLUP);
    
    }
    void loop() {
          SysexButtonmsg(); 
    
    }
    // The selectMuxPin function sets the S0, S1, and S2 pins
    // accordingly, given a pin from 0-7.
    void selectMuxPin(byte pin){
    { 
      for (int i = 0; i < 4; i++)
      {
        if (pin & (1 << i)){
          digitalWrite(selectPins1[i], HIGH);
          delayMicroseconds(10);
        }
        else {
          digitalWrite(selectPins1[i], LOW);
          delayMicroseconds(10);
        }
    
        if (pin & (1 << i)){
          digitalWrite(selectPins2[i], HIGH);
          delayMicroseconds(10);
        }
        else {
          digitalWrite(selectPins2[i], LOW);
          delayMicroseconds(10);
        }
      }
    }
    }
    //BUTTONS SYSEX COMMENDS 
    void SysexButtonmsg(){
      //MUX1
    
      // Loop through only the first five mux pins (last three are not connected)
      for (byte pin = 0; pin <= 15; pin++)
      {    
        // Effectively a 5ms debounce
        if ((millis() - msecMux1[pin]) >= 5) {
          selectMuxPin(pin); // Select one at a time
          buttonState1[pin] = digitalRead(zInput1); // and read Z
        
          if (buttonState1[pin] != buttonStatePrev1[pin]) {
            // If a button is pressed
       
       //SOLO BUTTONS
       
        if (buttonState1[0] == 0) {    
        byte solo1push[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo1push, true);
        }
        else {    
        byte solo1release[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo1release, true);
        }
        if (buttonState1[2] == 0) {
        byte solo2push[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo2push, true);
        }
        else { 
        byte solo2release[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo2release, true);
        }  
        if (buttonState1[4] == 0) {
        byte solo3push[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo3push, true);
        }
        else {   
        byte solo3release[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo3release, true);
        }   
        if (buttonState1[6] == 0) {
        byte solo4push[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo4push, true);
        }
        else { 
        byte solo4release[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo4release, true);
        }   
        if (buttonState1[8] == 0) {
        byte solo5push[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo5push, true);
        }
        else { 
        byte solo5release[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo5release, true);
        }   
        if (buttonState1[10] == 0) {
        byte solo6push[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo6push, true);
        }
        else { 
        byte solo6release[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo6release, true);
        }   
        if (buttonState1[12] == 0) {
        byte solo7push[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo7push, true);
        }
        else { 
        byte solo7release[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo7release, true);
        }   
        if (buttonState1[14] == 0) {
        byte solo8push[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo8push, true);
        }
        else { 
        byte solo8release[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, solo8release, true);
        }
         
    //MUTE BUTTONS
    
        if (buttonState1[1] == 0) {
        byte mute1push[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute1push, true);
        }
        else {
        byte mute1release[] = { 0xB0,0x0F,0x00, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute1release, true);
        }  
        if (buttonState1[3] == 0) {
        byte mute2push[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute2push, true);
        }
        else {
        byte mute2release[] = { 0xB0,0x0F,0x01, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute2release, true);
        }    
        if (buttonState1[5] == 0) {
        byte mute3push[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute3push, true);
        }
        else {
        byte mute3release[] = { 0xB0,0x0F,0x02, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute3release, true);
        }   
        if (buttonState1[7] == 0) {
        byte mute4push[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute4push, true);
        }
        else {
        byte mute4release[] = { 0xB0,0x0F,0x03, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute4release, true);
        }     
        if (buttonState1[9] == 0) {
        byte mute5push[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute5push, true);
        }
        else {   
        byte mute5release[] = { 0xB0,0x0F,0x04, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute5release, true);
        }      
        if (buttonState1[11] == 0) {
        byte mute6push[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute6push, true);
        }
        else {   
        byte mute6release[] = { 0xB0,0x0F,0x05, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute6release, true);
        }   
        if (buttonState1[13] == 0) {  
        byte mute7push[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute7push, true);
        }
        else { 
        byte mute7release[] = { 0xB0,0x0F,0x06, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute7release, true);
        }
        if (buttonState1[15] == 0) {  
        byte mute8push[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute8push, true);
        }
        else {     
        byte mute8release[] = { 0xB0,0x0F,0x07, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, mute8release, true);
        }
            msecMux1[pin] = millis();
            buttonStatePrev1[pin] = buttonState1[pin];
          }
        }
      }
    
      while (usbMIDI.read()) { 
      }
      delay(10);
    
    //TRANSPORT BUTTONS
    //MUX2
      // Loop through only the first five mux pins (last three are not connected)
      for (byte pin = 0; pin <= 15; pin++)
      {    
        // Effectively a 5ms debounce
        if ((millis() - msecMux2[pin]) >= 5) {
          selectMuxPin(pin); // Select one at a time
          buttonState2[pin] = digitalRead(zInput2); // and read Z
        
          if (buttonState2[pin] != buttonStatePrev2[pin]) {
            // If a button is pressed
    
        if (buttonState2[2] == 0) {  
        byte playpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, playpush, true);
        }
        else { 
        byte playrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, playrelease, true);
        }
        if (buttonState2[3] == 0) {  
        byte stoppush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, stoppush, true);
        }
        else { 
        byte stoprelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, stoprelease, true);
        }
        
        if (buttonState2[1] == 0) {  
        byte fastfwdpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, fastfwdpush, true);
        }
        else { 
        byte fastfwdrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, fastfwdrelease, true);
        }
        if (buttonState2[0] == 0) {  
        byte rewindpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, rewindpush, true);
        }
        else { 
        byte rewindrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, rewindrelease, true);
        }
        
        if (buttonState2[4] == 0) {  
        byte recpush[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x45}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, recpush, true);
        }
        else { 
        byte recrelease[] = { 0xB0,0x0F,0x0e, 0xB0,0x2F,0x05}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, recrelease, true);
        }
        if (buttonState2[5] == 0) {  
        byte qckpnchpush[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, qckpnchpush, true);
        }
        else { 
        byte qckpnchrelease[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, qckpnchrelease, true);
        }
        if (buttonState2[6] == 0) {  
        byte looppush[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, looppush, true);
        }
        else { 
        byte looprelease[] = { 0xB0,0x0F,0x0f, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, looprelease, true);
        }
    
    // READ TOUCH LATCH WRITE
      
        if (buttonState2[7] == 0) {  
        byte readpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, readpush, true);
        }
        else { 
        byte readrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, readrelease, true);
        }
        if (buttonState2[8] == 0) {  
        byte touchpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x45}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, touchpush, true);
        }
        else { 
        byte touchrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x05}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, touchrelease, true);
        }
        if (buttonState2[9] == 0) {  
        byte latchpush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, latchpush, true);
        }
        else { 
        byte latchrelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, latchrelease, true);
        }
        if (buttonState2[10] == 0) {  
        byte writepush[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x44}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, writepush, true);
        }
        else { 
        byte writerelease[] = { 0xB0,0x0F,0x18, 0xB0,0x2F,0x04}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, writerelease, true);
        }
    
    //BANKS LEFT RIGHT
       
        if (buttonState2[13] == 0) {  
        byte  chanl1leftpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x41}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1leftpush, true);
        }
        else {
        byte chanl1leftrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x01}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1leftrelease, true);
        }
        if (buttonState2[14] == 0) {  
        byte  chanl8leftpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x40}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8leftpush, true);
        }
        else {
        byte chanl8leftrelease[] = {0xB0,0x0F,0x0a, 0xB0,0x2F,0x00}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8leftrelease, true);
        }
        if (buttonState2[11] == 0) {  
        byte  chanl1rightpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x42}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1rightpush, true);
        }
        else {
        byte chanl1rightrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x02}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl1rightrelease, true);
        }
        if (buttonState2[12] == 0) {  
        byte  chanl8rightpush[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x43}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8rightpush, true);
        }
        else {
        byte chanl8rightrelease[] = { 0xB0,0x0F,0x0a, 0xB0,0x2F,0x03}; // ACK msg - should be safe for any device even if listening for 7D
        usbMIDI.sendSysEx(6, chanl8rightrelease, true);
        }
                msecMux2[pin] = millis();
            buttonStatePrev2[pin] = buttonState2[pin];
          }
        }
      }
    
      while (usbMIDI.read()) {
      
        // ignore incoming messages
      }
      delay(10);
    }
    tnx
    rota
    Last edited by rotabox; 03-07-2019 at 10:54 PM.

  2. #2
    ok i find out that my routing of 2 multiplexers is not like it should be i now connect 2 cd74hc4067 to teensy 3.6
    when mux1 0S 01 02 03 connected to mux2 0S 01 02 03 that connected to pins 24 25 26 27 on teensy
    the z of mux 1 connected to pin 13
    the z of mux 2 connected to pin 28

    theres any example code for using 2 multiplexer that way?

    i use this chematic
    Click image for larger version. 

Name:	Screen Shot 2019-03-08 at 2.12.42 PM.jpg 
Views:	18 
Size:	100.9 KB 
ID:	16100
    Last edited by rotabox; 03-08-2019 at 12:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •