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

Thread: porting midi controller code over from an Arduino Due. Need some help

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    4

    porting midi controller code over from an Arduino Due. Need some help

    Hi Folks,
    I am in need of some help here. I am building a midi mixer for the visually impaired and am using some code that was originally written for an Arduino Due.
    The code basically strobes multiple 4067 multiplexer chips (I have designed a 96 way multiplexer board if anyone wants the design please PM me) and then dependant on the value returned ( a variable voltage between 0 and 3.3v for pots and 0 or 3.3v for switches) output a midi message. I have used the code very successfully on other projects but this project requires 44 pots and 33 switches to be scanned which would be pushing the limit of the Arduino whereas the Teensy (4.0) looks it could handle this code and a bit more without breaking a sweat.
    Now to the problem;

    I have compiled the sketch with a few changes to accommodate the change in the amount of switches and pots but when I try to verify the script the IDE is reporting the following errors;


    Arduino: 1.8.10 (Windows 10), TD: 1.48, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"

    Midi_Multiplexer_backup: In function 'void updateButtons()':
    Midi_Multiplexer_backup:205: warning: array subscript is above array bounds
    byte message = BUTTONS[i]->getValue();

    ^

    Midi_Multiplexer_backup:209: warning: array subscript is above array bounds
    switch (BUTTONS[i]->Bcommand) {

    ^

    Midi_Multiplexer_backup:219: warning: array subscript is above array bounds
    BUTTONS[i]->Btoggle = 1;

    ^

    Midi_Multiplexer_backup:223: warning: array subscript is above array bounds
    BUTTONS[i]->Btoggle = 0;

    ^

    Midi_Multiplexer_backup:231: warning: array subscript is above array bounds
    switch (BUTTONS[i]->Bcommand) {

    ^

    Midi_Multiplexer_backup: In function 'void updatePots()':
    Midi_Multiplexer_backup:288: warning: array subscript is above array bounds
    byte potmessage = POTS[i]->getValue();

    ^

    Midi_Multiplexer_backup:289: warning: array subscript is above array bounds
    if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);

    ^

    C:\Users\User\AppData\Local\Temp\arduino_build_730 605\sketch\Controller.cpp: In member function 'byte Button::getValue()':

    Controller.cpp:96: warning: comparison between signed and unsigned integer expressions
    if (millis() - _time < _debounce) return 255;

    ^

    C:\Users\rayev\AppData\Local\Temp\arduino_build_73 0605\sketch\Controller.cpp: In member function 'void Pot::muxUpdate()':

    Controller.cpp:140: error: 'PORTD' was not declared in this scope
    if (_numMuxPins > 8) PORTD = PORTD & B11000011;

    ^

    Controller.cpp:141: error: 'PORTD' was not declared in this scope
    else PORTD = PORTD & B11100011;

    ^

    Controller.cpp:143: error: 'PORTD' was not declared in this scope
    PORTD = PORTD | temp;

    ^

    Multiple libraries were found for "MIDI.h"
    Used: C:\Program
    Not used: C:\Users\User\OneDrive\Documents\Arduino\libraries \MIDI_Library
    'PORTD' was not declared in this scope

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.


    I have attached the main code plus the Controller.cpp and Controller.h subscripts

    I understand some of the code and am trying to get to grips with the rest but this has me stumped.
    One line does spring out though;

    C:\Users\User\AppData\Local\Temp\arduino_build_730 605\sketch\Controller.cpp: In member function 'byte Button::getValue()':

    Does the part "arduino_build_730605" need to be changed to Teensy?

    Any suggestions on how to change this to get it working on the Teensy would be greatly appreciated

    Cheers.
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,178
    Code:
    //***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************
    //Pot (Pin Number, Command, CC Control, Channel Number)
    //**Command parameter is for future use**
    
    //Pot PO1(A0, 0, 1, 1);
    //Pot PO2(A1, 0, 10, 1);
    //Pot PO3(A2, 0, 22, 1);
    //Pot PO4(A3, 0, 118, 1);
    //Pot PO5(A4, 0, 30, 1);
    //Pot PO6(A5, 0, 31, 1);
    //*******************************************************************
    //Add pots used to array below like this->  Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6};
    Pot *POTS[] {};
    //*******************************************************************
    
    
    //***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
    //Button (Pin Number, Command, Note Number, Channel, Debounce Time)
    //** Command parameter 0=NOTE  1=CC  2=Toggle CC **
    
    //Button BU1(2, 0, 60, 1, 5 );
    //Button BU2(3, 0, 61, 1, 5 );
    //Button BU3(4, 0, 62, 1, 5 );
    //Button BU4(5, 0, 63, 1, 5 );
    //Button BU5(6, 0, 64, 1, 5 );
    //Button BU6(7, 0, 65, 1, 5 );
    //Button BU7(8, 1, 64, 1, 5 );
    //Button BU8(9, 2, 64, 1, 5 );
    //*******************************************************************
    //Add buttons used to array below like this->  Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
    Button *BUTTONS[] {};
    //*******************************************************************
    You haven't done what the comments say. Both the POTS and BUTTONS arrays are declared to be of length zero. You need to declare, for example, some buttons like this:
    Code:
    Button BU1(2, 0, 60, 1, 5 );
    Button BU2(3, 0, 61, 1, 5 );
    Button BU3(4, 0, 62, 1, 5 );
    and then put them in the BUTTONS array:
    Code:
    Button *BUTTONS[] {&BU1, &BU2, &BU3};
    In the case of the BUTTONS, you will have to change the pin numbers (first number) and the other parameters to suit your installation.

    Similar work needs to be done with the POTS array.

    You will also have a different problem with PORTD. The T4 doesn't appear to have a PORTD. You'll have to figure out what PORTD does on the Due and then replicate that on the T4.

    Code:
    C:\Users\User\AppData\Local\Temp\arduino_build_730 605\sketch\Controller.cpp
    This path suggests that you have used the system installation version of the Arduino IDE (as opposed to the zip install).
    The "arduino_build_730 605" is an arbitrary directory name generated by the IDE for this compilation session.

    Pete

  3. #3
    Junior Member
    Join Date
    Nov 2019
    Posts
    4

    Thanks Pete

    Quote Originally Posted by el_supremo View Post
    Code:
    //***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************
    //Pot (Pin Number, Command, CC Control, Channel Number)
    //**Command parameter is for future use**
    
    //Pot PO1(A0, 0, 1, 1);
    //Pot PO2(A1, 0, 10, 1);
    //Pot PO3(A2, 0, 22, 1);
    //Pot PO4(A3, 0, 118, 1);
    //Pot PO5(A4, 0, 30, 1);
    //Pot PO6(A5, 0, 31, 1);
    //*******************************************************************
    //Add pots used to array below like this->  Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6};
    Pot *POTS[] {};
    //*******************************************************************
    
    
    //***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
    //Button (Pin Number, Command, Note Number, Channel, Debounce Time)
    //** Command parameter 0=NOTE  1=CC  2=Toggle CC **
    
    //Button BU1(2, 0, 60, 1, 5 );
    //Button BU2(3, 0, 61, 1, 5 );
    //Button BU3(4, 0, 62, 1, 5 );
    //Button BU4(5, 0, 63, 1, 5 );
    //Button BU5(6, 0, 64, 1, 5 );
    //Button BU6(7, 0, 65, 1, 5 );
    //Button BU7(8, 1, 64, 1, 5 );
    //Button BU8(9, 2, 64, 1, 5 );
    //*******************************************************************
    //Add buttons used to array below like this->  Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
    Button *BUTTONS[] {};
    //*******************************************************************
    You haven't done what the comments say. Both the POTS and BUTTONS arrays are declared to be of length zero. You need to declare, for example, some buttons like this:
    Code:
    Button BU1(2, 0, 60, 1, 5 );
    Button BU2(3, 0, 61, 1, 5 );
    Button BU3(4, 0, 62, 1, 5 );
    and then put them in the BUTTONS array:
    Code:
    Button *BUTTONS[] {&BU1, &BU2, &BU3};
    In the case of the BUTTONS, you will have to change the pin numbers (first number) and the other parameters to suit your installation.

    Similar work needs to be done with the POTS array.

    You will also have a different problem with PORTD. The T4 doesn't appear to have a PORTD. You'll have to figure out what PORTD does on the Due and then replicate that on the T4.

    Code:
    C:\Users\User\AppData\Local\Temp\arduino_build_730 605\sketch\Controller.cpp
    This path suggests that you have used the system installation version of the Arduino IDE (as opposed to the zip install).
    The "arduino_build_730 605" is an arbitrary directory name generated by the IDE for this compilation session.

    Pete
    Thanks Pete,
    I am not using any direct connected Pots or Buttons, they are all connected via the multiplexers - should I still put something in for the pots and buttons even though there arent any? Also do you think it might help if I completely uninstalled the Arduino IDE and its libraries and start again with a more rational installation that didnt use the Onedrive to reference certain things (I hadnt noticed the install had done this).
    I will also look into the part of the code that references Port D and as you suggest, figure out what it does on the Due.

    Thanks for your help.
    Ray

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,178
    See if this gets rid of the errors with BUTTONS and POTS. I've just commented out the code that uses them.
    Code:
    #include <MIDI.h>
    #include "Controller.h"
    
    /*************************************************************
      MIDI CONTROLLER
    
      by Notes and Volts
      www.notesandvolts.com
    
      Version 1.2 **Arduino UNO ONLY!**
     *************************************************************/
    
    MIDI_CREATE_DEFAULT_INSTANCE();
    
    //************************************************************
    //***SET THE NUMBER OF CONTROLS USED**************************
    //************************************************************
    //---How many buttons are connected directly to pins?---------
    //byte NUMBER_BUTTONS = 0;
    //---How many potentiometers are connected directly to pins?--
    //byte NUMBER_POTS = 0;
    //---How many buttons are connected to a multiplexer?---------
    byte NUMBER_MUX_BUTTONS = 32;
    //---How many potentiometers are connected to a multiplexer?--
    byte NUMBER_MUX_POTS = 44;
    //************************************************************
    
    //***ANY MULTIPLEXERS? (74HC4067)************************************
    //MUX address pins must be connected to Arduino UNO pins 2,3,4,5
    //A0 = PIN2, A1 = PIN3, A2 = PIN4, A3 = PIN5
    //*******************************************************************
    //Mux NAME (OUTPUT PIN, , How Many Mux Pins?(8 or 16) , Is It Analog?);
    
    
    Mux M1(A0, 16, true); //Analog multiplexer on Arduino analog pin A0
    Mux M2(A1, 16, true); //Analog multiplexer on Arduino analog pin A1
    Mux M3(A2, 16, true); //Analog multiplexer on Arduino analog pin A2
    Mux M4(A3, 16, false); //Analog multiplexer on Arduino digital pin A3
    Mux M5(A4, 16, false); //Analog multiplexer on Arduino digital pin A4
    //*******************************************************************
    
    
    //***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************
    //Pot (Pin Number, Command, CC Control, Channel Number)
    //**Command parameter is for future use**
    
    //Pot PO1(A0, 0, 1, 1);
    //Pot PO2(A1, 0, 10, 1);
    //Pot PO3(A2, 0, 22, 1);
    //Pot PO4(A3, 0, 118, 1);
    //Pot PO5(A4, 0, 30, 1);
    //Pot PO6(A5, 0, 31, 1);
    //*******************************************************************
    //Add pots used to array below like this->  Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6};
    //Pot *POTS[] {};
    //*******************************************************************
    
    
    //***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
    //Button (Pin Number, Command, Note Number, Channel, Debounce Time)
    //** Command parameter 0=NOTE  1=CC  2=Toggle CC **
    
    //Button BU1(2, 0, 60, 1, 5 );
    //Button BU2(3, 0, 61, 1, 5 );
    //Button BU3(4, 0, 62, 1, 5 );
    //Button BU4(5, 0, 63, 1, 5 );
    //Button BU5(6, 0, 64, 1, 5 );
    //Button BU6(7, 0, 65, 1, 5 );
    //Button BU7(8, 1, 64, 1, 5 );
    //Button BU8(9, 2, 64, 1, 5 );
    //*******************************************************************
    //Add buttons used to array below like this->  Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
    //Button *BUTTONS[] {};
    //*******************************************************************
    
    
    //***DEFINE BUTTONS CONNECTED TO MULTIPLEXER*************************
    //Button::Button(Mux mux, byte muxpin, byte command, byte value, byte channel, byte debounce)
    //** Command parameter 0=NOTE  1=CC  2=Toggle CC **
    
    Button MBU1(M4, 0, 0, 70, 1, 5);
    Button MBU2(M4, 1, 1, 71, 1, 5);
    Button MBU3(M4, 2, 2, 72, 1, 5);
    Button MBU4(M4, 3, 0, 73, 1, 5);
    Button MBU5(M4, 4, 0, 74, 1, 5);
    Button MBU6(M4, 5, 0, 75, 1, 5);
    Button MBU7(M4, 6, 0, 76, 1, 5);
    Button MBU8(M4, 7, 0, 77, 1, 5);
    Button MBU9(M4, 8, 0, 78, 1, 5);
    Button MBU10(M4, 9, 0, 79, 1, 5);
    Button MBU11(M4, 10, 0, 80, 1, 5);
    Button MBU12(M4, 11, 0, 81, 1, 5);
    Button MBU13(M4, 12, 0, 82, 1, 5);
    Button MBU14(M4, 13, 0, 83, 1, 5);
    Button MBU15(M4, 14, 0, 84, 1, 5);
    Button MBU16(M4, 15, 0, 85, 1, 5);
    Button MBU17(M5, 0, 0, 70, 1, 5);
    Button MBU18(M5, 1, 1, 71, 1, 5);
    Button MBU19(M5, 2, 2, 72, 1, 5);
    Button MBU20(M5, 3, 0, 73, 1, 5);
    Button MBU21(M5, 4, 0, 74, 1, 5);
    Button MBU22(M5, 5, 0, 75, 1, 5);
    Button MBU23(M5, 6, 0, 76, 1, 5);
    Button MBU24(M5, 7, 0, 77, 1, 5);
    Button MBU25(M5, 8, 0, 78, 1, 5);
    Button MBU26(M5, 9, 0, 79, 1, 5);
    Button MBU27(M5, 10, 0, 80, 1, 5);
    Button MBU28(M5, 11, 0, 81, 1, 5);
    Button MBU29(M5, 12, 0, 82, 1, 5);
    Button MBU30(M5, 13, 0, 83, 1, 5);
    Button MBU31(M5, 14, 0, 84, 1, 5);
    Button MBU32(M5, 15, 0, 85, 1, 5);
    //*******************************************************************
    ////Add multiplexed buttons used to array below like this->  Button *MUXBUTTONS[] {&MBU1, &MBU2, &MBU3, &MBU4, &MBU5, &MBU6.....};
    Button *MUXBUTTONS[] {&MBU1, &MBU2, &MBU3, &MBU4, &MBU5, &MBU6, &MBU7, &MBU8, &MBU9, &MBU10, &MBU11, &MBU12, &MBU13, &MBU14, &MBU15, &MBU16, &MBU17, &MBU18, &MBU19, &MBU20, &MBU21, &MBU22, &MBU23, &MBU24, &MBU25, &MBU26, &MBU27, &MBU28, &MBU29, &MBU30, &MBU31, &MBU32};
    
    //*******************************************************************
    
    
    //***DEFINE POTENTIOMETERS CONNECTED TO MULTIPLEXER*******************
    //Pot::Pot(Mux mux, byte muxpin, byte command, byte control, byte channel)
    //**Command parameter is for future use**
    
    Pot MPO1(M1, 0, 0, 77, 1);
    Pot MPO2(M1, 1, 0, 82, 1);
    Pot MPO3(M1, 2, 0, 14, 1);
    Pot MPO4(M1, 3, 0, 19, 1);
    Pot MPO5(M1, 4, 0, 15, 1);
    Pot MPO6(M1, 5, 0, 22, 1);
    Pot MPO7(M1, 6, 0, 5, 1);
    Pot MPO8(M1, 7, 0, 18, 1);
    Pot MPO9(M1, 8, 0, 20, 1);
    Pot MPO10(M1, 9, 0, 21, 1);
    Pot MPO11(M1, 10, 0, 28, 1);
    Pot MPO12(M1, 11, 0, 74, 1);
    Pot MPO13(M1, 12, 0, 29, 1);
    Pot MPO14(M1, 13, 0, 71, 1);
    Pot MPO15(M1, 14, 0, 12, 1);
    Pot MPO16(M1, 15, 0, 93, 1);
    Pot MPO17(M2, 0, 0, 30, 1);
    Pot MPO18(M2, 1, 0, 31, 1);
    Pot MPO19(M2, 2, 0, 85, 1);
    Pot MPO20(M2, 3, 0, 79, 1);
    Pot MPO21(M2, 4, 0, 76, 1);
    Pot MPO22(M2, 5, 0, 27, 1);
    Pot MPO23(M2, 6, 0, 24, 1);
    Pot MPO24(M2, 7, 0, 23, 1);
    Pot MPO25(M2, 8, 0, 26, 1);
    Pot MPO26(M2, 9, 0, 25, 1);
    Pot MPO27(M2, 10, 0, 73, 1);
    Pot MPO28(M2, 11, 0, 75, 1);
    Pot MPO29(M2, 12, 0, 70, 1);
    Pot MPO30(M2, 13, 0, 72, 1);
    Pot MPO31(M2, 14, 0, 72, 1);
    Pot MPO32(M2, 15, 0, 70, 1);
    Pot MPO33(M3, 0, 0, 30, 1);
    Pot MPO34(M3, 1, 0, 31, 1);
    Pot MPO35(M3, 2, 0, 85, 1);
    Pot MPO36(M3, 3, 0, 79, 1);
    Pot MPO37(M3, 4, 0, 76, 1);
    Pot MPO38(M3, 5, 0, 27, 1);
    Pot MPO39(M3, 6, 0, 24, 1);
    Pot MPO40(M3, 7, 0, 23, 1);
    Pot MPO41(M3, 8, 0, 26, 1);
    Pot MPO42(M3, 9, 0, 25, 1);
    Pot MPO43(M3, 10, 0, 73, 1);
    //Pot MPO44(M3, 11, 0, 75, 1);
    //Pot MPO45(M3, 12, 0, 70, 1);
    //Pot MPO46(M3, 13, 0, 72, 1);
    //Pot MPO29(M3, 15, 0, 70, 1);
    //Pot MPO30(M3, 15, 0, 72, 1);
    //Pot MPO31(M4, 6, 0, 7, 1);
    //Pot MPO32(M4, 7, 0, 5, 1);
    //Pot MPO9(M2, 8, 0, 50, 1);
    //Pot MPO10(M2, 9, 0, 55, 2);
    //Pot MPO11(M2, 10, 0, 50, 1);
    //Pot MPO12(M2, 11, 0, 55, 2);
    //Pot MPO13(M2, 12, 0, 50, 1);
    //Pot MPO14(M2, 13, 0, 55, 2);
    //Pot MPO15(M2, 14, 0, 50, 1);
    //Pot MPO16(M2, 15, 0, 55, 2);
    //*******************************************************************
    //Add multiplexed pots used to array below like this->  Pot *MUXPOTS[] {&MPO1, &MPO2, &MPO3, &MPO4, &MPO5, &MPO6.....};
    Pot *MUXPOTS[] {&MPO1, &MPO2, &MPO3, &MPO4, &MPO5, &MPO6, &MPO7, &MPO8, &MPO9, &MPO10, &MPO11, &MPO12, &MPO13, &MPO14, &MPO15, &MPO16, &MPO17, &MPO18, &MPO19, &MPO20, &MPO21, &MPO22, &MPO23, &MPO24, &MPO25, &MPO26, &MPO27, &MPO28, &MPO29, &MPO30, &MPO31, &MPO32, &MPO33, &MPO34, &MPO35, &MPO36, &MPO37, &MPO38, &MPO39, &MPO40, &MPO41, &MPO42, &MPO43,};
    //*******************************************************************
    
    
    void setup() {
      MIDI.begin(MIDI_CHANNEL_OFF);
    }
    
    void loop() {
    /*	
      if (NUMBER_BUTTONS != 0) updateButtons();
      if (NUMBER_POTS != 0) updatePots();
    */
      if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
      if (NUMBER_MUX_POTS != 0) updateMuxPots();
    }
    
    
    //*****************************************************************
    /*
    void updateButtons() {
    
      // Cycle through Button array
      for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
        byte message = BUTTONS[i]->getValue();
    
        //  Button is pressed
        if (message == 0) {
          switch (BUTTONS[i]->Bcommand) {
            case 0: //Note
              MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
              break;
            case 1: //CC
              MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
              break;
            case 2: //Toggle
              if (BUTTONS[i]->Btoggle == 0) {
                MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
                BUTTONS[i]->Btoggle = 1;
              }
              else if (BUTTONS[i]->Btoggle == 1) {
                MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
                BUTTONS[i]->Btoggle = 0;
              }
              break;
          }
        }
    
        //  Button is not pressed
        if (message == 1) {
          switch (BUTTONS[i]->Bcommand) {
            case 0:
              MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
              break;
            case 1:
              MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
              break;
          }
        }
      }
    }
    */
    
    
    //*******************************************************************
    void updateMuxButtons() {
    
      // Cycle through Mux Button array
      for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {
    
        MUXBUTTONS[i]->muxUpdate();
        byte message = MUXBUTTONS[i]->getValue();
    
        //  Button is pressed
        if (message == 0) {
          switch (MUXBUTTONS[i]->Bcommand) {
            case 0: //Note
              MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
              break;
            case 1: //CC
              MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
              break;
            case 2: //Toggle
              if (MUXBUTTONS[i]->Btoggle == 0) {
                MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
                MUXBUTTONS[i]->Btoggle = 1;
              }
              else if (MUXBUTTONS[i]->Btoggle == 1) {
                MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
                MUXBUTTONS[i]->Btoggle = 0;
              }
              break;
          }
        }
        //  Button is not pressed
        if (message == 1) {
          switch (MUXBUTTONS[i]->Bcommand) {
            case 0:
              MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
              break;
            case 1:
              MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
              break;
          }
        }
      }
    }
    
    /*
    //***********************************************************************
    void updatePots() {
      for (int i = 0; i < NUMBER_POTS; i = i + 1) {
        byte potmessage = POTS[i]->getValue();
        if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
      }
    }
    */
    
    
    //***********************************************************************
    void updateMuxPots() {
      for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
        MUXPOTS[i]->muxUpdate();
        byte potmessage = MUXPOTS[i]->getValue();
        if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage, MUXPOTS[i]->Pchannel);
      }
    }

    I always use a ZIP install of the Arduino IDE. It allows me to have multiple versions without them interfering with each other and I can install them where I want them. But the install itself isn't a problem for you right now. Unless the installation somehow does become an issue, I'd leave it alone and get the code working.

    There's also references to PORTA in controller.cpp. It looks like the code is just using PORTA and PORTD to directly meddle with pins on the multiplexer so you just need to replicate it on the T4.

    Pete

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,845
    For cases like this using the PORTD register...

    Code:
    PORTD = PORTD & B11100011;
    I'd recommend investing a little time to figure out which 3 pins that really drives low and replace it with code like this: (if pins 1, 2, 3)

    Code:
    digitalWriteFast(1, LOW);
    digitalWriteFast(2, LOW);
    digitalWriteFast(3, LOW);
    Sure, you could go to the trouble of grouping signals on ports and adapting the code to native port registers. But that's a lot of work which results in even more code that's hard to figure out what it really does. Going with digitalWriteFast() gives you an extremely fast version that it much easier to understand and adapt in the future.

  6. #6
    Junior Member
    Join Date
    Nov 2019
    Posts
    4
    Thanks Paul, much appreciated.
    I am relatively new to coding so progress is slow but the help you and El supremo have given me so far is invaluable.
    The reason I chose the Teensy over the Arduino is because I want a scalable design that would just let me dial in as many inputs/outputs as I needed, the Arduino seems to reach its limit with 4 multiplexers whereas my designs use between 5-15 multiplexers and your Teensy seemed the perfect candidate with horsepower to spare - some of which will be utilised to strobe display led's (PWM and static) but that's the next stage after I have this figured out.

    Cheers
    Ray

  7. #7
    Junior Member
    Join Date
    Nov 2019
    Posts
    4
    Thanks Pete, I will try this today.
    Cheers
    Ray

Posting Permissions

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