Need coding help and modding Mixman DM2 DJ Gear.

Status
Not open for further replies.

Demonclaw

Active member
I personally own a Mixman DM2 Dj gear thing and since there is no way for it to work on anything newer then XP. Instead of trashing it I decided I could mod it to work on any OS I choose. I took the main board out and throw it in my parts bin and turned to the Teensy 2.0 ++ as the new main board for it. I made a custom new board with the Teensy solder to it. I'm running into some snags with the coding since I don't really have a lot of pins on the Teensy I can work with so I'm working with a 74HC4051 chip to add more pins to the Teensy. I'm coding on a Windows 8. I need to get a 74HC4051 chip to work with the Teensy and I'm not sure if my code would work. It's written in Arduino programming language. Version of Arduino program is 1.6.7 with Teensyduino 1.27 installed.


Photo-0021.jpg

Not in the picture are the 2 midi ports and the 2 add buttons.


So here is the the break down of what is attached to the Teensy:

teensy_attachments.png

  • 2 MIDI ports (1 for input and 1 out put)
  • 33 butttons
  • 2 encoders
  • 1 linear slide potentiometer
  • 16 Led's
  • 3 74HC4051

---------------------------------------------------------------------------------
Going to add later on.
---------------------------------------------------------------------------------

  • 16 ( More ) linear slide potentiometer
  • 24 potentiometer
  • 5 ( More ) 74HC4051


here is the code I have so far.

Code:
#include <Bounce.h>

//#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>

//midi pass thru 
#include <MIDI.h>

// define how many pots are active up to number of available analog inputs
#define analogInputs 8

//midi pass thru
int chnl,d1,d2,dd;

// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];

// 74HC4051 chip
int chipselect = 0

// make array of cc values
int ccValue[analogInputs];

// index variable for loop
int i;

// cc values for buttons
int cc_off = 0;
int cc_on = 65;
int cc_super = 127;

// map buttons to cc for button 
//(add more buttons here)
int cc0 = 51;
int cc1 = 52;
int cc2 = 53;
int cc3 = 54; 
int cc4 = 55; 
int cc5 = 56;
int cc6 = 57;
int cc7 = 58;
int cc8 = 59;
int cc9 = 60;
int cc10 = 61;
int cc11 = 62;
int cc12 = 63;
int cc13 = 64;
int cc14 = 65;
int cc15 = 66;
int cc16 = 67;
int cc17 = 68;
int cc18 = 69;
int cc19 = 70;
int cc20 = 71;
int cc21 = 72;
int cc22 = 73;
int cc23 = 74;
int cc24 = 75;
int cc25 = 76;
int cc26 = 77;
int cc27 = 78;

/* Encoder Library - TwoKnobs Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * This example code is in the public domain.
 */
// Change these pin numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder knobLeft(0, 1);
Encoder knobRight(18, 19);

//   avoid using pins with LEDs attached
//(add more buttons here)
//Bounce button0 = Bounce(4, 3);
//Bounce button1 = Bounce(5, 3);
//Bounce button2 = Bounce(7, 3);
Bounce button3 = Bounce(8, 3);
Bounce button4 = Bounce(9, 3);
Bounce button5 = Bounce(10, 3);
Bounce button6 = Bounce(11, 3);
Bounce button7 = Bounce(12, 3);
Bounce button8 = Bounce(13, 3);
Bounce button9 = Bounce(14, 3);
Bounce button10 = Bounce(15, 3);
Bounce button11 = Bounce(16, 3);
Bounce button12 = Bounce(17, 3);
Bounce button13 = Bounce(20, 3);
Bounce button14 = Bounce(21, 3);
Bounce button15 = Bounce(22, 3);
Bounce button16 = Bounce(23, 3);
Bounce button17 = Bounce(24, 3);
Bounce button18 = Bounce(25, 3);
Bounce button19 = Bounce(26, 3);
Bounce button20 = Bounce(28, 3);
Bounce button21 = Bounce(29, 3);
Bounce button22 = Bounce(30, 3);
Bounce button23 = Bounce(31, 3);
Bounce button24 = Bounce(32, 3);
Bounce button25 = Bounce(33, 3);
Bounce button26 = Bounce(34, 3);
Bounce button27 = Bounce(35, 3);

//midi pass thru 
kMIDIType type;
void setup() {
  // MIDI rate
  //Serial.begin(31250);
  //debug serial
Serial.begin(9600);

  
  Serial.println("TwoKnobs Encoder Test:");
// pins for buttons, sliders, and pots
//  pinMode(0, INPUT_PULLUP);
//  pinMode(1, INPUT_PULLUP);
//  pinMode(2, INPUT_PULLUP);
//  pinMode(3, INPUT_PULLUP);
 // pinMode(4, INPUT_PULLUP);
 // pinMode(5, INPUT_PULLUP);
//  pinMode(6, INPUT_PULLUP); led pin
 // pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  pinMode(23, INPUT_PULLUP);
  pinMode(24, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
  pinMode(27, INPUT_PULLUP); // the common pin from the 74HC4051
  pinMode(28, INPUT_PULLUP);
  pinMode(29, INPUT_PULLUP);
  pinMode(30, INPUT_PULLUP);
  pinMode(31, INPUT_PULLUP);
  pinMode(32, INPUT_PULLUP);
  pinMode(33, INPUT_PULLUP);
  pinMode(34, INPUT_PULLUP);
  pinMode(35, INPUT_PULLUP);

// Anaglog
  pinMode(38, INPUT_PULLUP);
//  pinMode(39, INPUT_PULLUP);
//  pinMode(40, INPUT_PULLUP);
//  pinMode(41, INPUT_PULLUP);
//  pinMode(42, INPUT_PULLUP);
//  pinMode(43, INPUT_PULLUP);
//  pinMode(44, INPUT_PULLUP);
//  pinMode(45, INPUT_PULLUP);


  
}

long positionLeft  = -999;
long positionRight = -999;

void loop() {
// 74HC4051 chip
switch (chipselect) {
    case 0:
      // pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 1:
         pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 2:
      // pinMode(4, OUTPUT);
         pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 3:
         pinMode(4, OUTPUT);
         pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 4:
      // pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
         pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 5:
         pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
         pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 6:
      // pinMode(4, OUTPUT);
         pinMode(5, OUTPUT);
         pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 7:
         pinMode(4, OUTPUT);
         pinMode(5, OUTPUT);
         pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    default: 
     chipselect = 0
    break;
  }


//midi pass thru
  if (MIDI.read() &&  MIDI.getType() < SystemExclusive) {
    type = MIDI.getType();
    d1 = MIDI.getData1();
    d2 = MIDI.getData2();
    dd = d1 + (d2 << 8);
    chnl = MIDI.getChannel();
    // and then send...
    switch(type){
      case NoteOn:
        usbMIDI.sendNoteOn(d1,d2,chnl);
      break;
      case NoteOff:
        usbMIDI.sendNoteOff(d1,d2,chnl);
      break;
      case AfterTouchPoly:
        usbMIDI.sendPolyPressure(d1,d2,chnl);
      break;
      case ControlChange:
        usbMIDI.sendControlChange(d1,d2,chnl);
      break;
      case ProgramChange:
        usbMIDI.sendProgramChange(dd,chnl);
      break;
      case AfterTouchChannel:
        usbMIDI.sendAfterTouch(dd,chnl);
      break;
      case PitchBend:
        
        usbMIDI.sendPitchBend(dd,chnl);
      break;
      case SystemExclusive:
        // handle sysex
      break;
      default:
        // F8 et seq.
      break;
    }
  }
  if (usbMIDI.read() &&  usbMIDI.getType() < SystemExclusive) {
    type = (kMIDIType) usbMIDI.getType();
    d1 = usbMIDI.getData1();
    d2 = usbMIDI.getData2();
    
    chnl = usbMIDI.getChannel();
    // and then send...
    MIDI.send(type,d1,d2,chnl);
  }


//scratch wheel
long newLeft, newRight;
  newLeft = knobLeft.read();
newRight = knobRight.read();
  if (newLeft != positionLeft || newRight != positionRight) {
    Serial.print("Left = ");
    Serial.print(newLeft);
 Serial.print(", Right = ");
 Serial.print(newRight);
    Serial.println();
    positionLeft = newLeft;
    positionRight = newRight;
}
  // if a character is sent from the serial monitor,
  // reset both back to zero.
  if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knobLeft.write(0);
    knobRight.write(0);
  }
  
  // loop trough active inputs for knobs
  for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
      // calc the CC value based on the raw value
      ccValue[i] = inputAnalog[i]/8;
      // send the MIDI
      usbMIDI.sendControlChange(i, ccValue[i], 3);
      // set raw reading to lagged array for next comparison
      iAlag[i] = inputAnalog[i];
    }
  delay(5); // limits MIDI messages to reasonable number
  }
  
  // Push Button code
  //(add more buttons here)
//  button0.update();
//  button1.update();
//  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();
  button12.update();
  button13.update();
  button14.update();
  button15.update();
  button16.update();
  button17.update();
  button18.update();
  button19.update();
  button20.update();
  button21.update();
  button22.update();
  button23.update();
  button24.update();
  button25.update();
  button26.update();
  button27.update();

 //(add more buttons here)
//   if (button0.fallingEdge())
//  {
//    usbMIDI.sendControlChange(cc0, cc_on, 3);
//  }
//  if (button1.fallingEdge())
//  {
//    usbMIDI.sendControlChange(cc1, cc_on, 3);
//  }
//  if (button2.fallingEdge())
//  {
//    usbMIDI.sendControlChange(cc2, cc_on, 3);
//  }
  if (button3.fallingEdge())
  {
    usbMIDI.sendControlChange(cc3, cc_on, 3);
  }
  if (button4.fallingEdge())
  {
    usbMIDI.sendControlChange(cc4, cc_on, 3);
  }
  if (button5.fallingEdge())
  {
    usbMIDI.sendControlChange(cc5, cc_on, 3);
  }
  if (button6.fallingEdge())
  {
    usbMIDI.sendControlChange(cc6, cc_on, 3);
  }
  if (button7.fallingEdge())
  {
    usbMIDI.sendControlChange(cc7, cc_on, 3);
  }
  if (button8.fallingEdge())
  {
    usbMIDI.sendControlChange(cc8, cc_on, 3);
  }
  if (button9.fallingEdge())
  {
    usbMIDI.sendControlChange(cc9, cc_on, 3);
  }
  if (button10.fallingEdge())
  {
    usbMIDI.sendControlChange(cc10, cc_on, 3);
  }
  if (button11.fallingEdge())
  {
    usbMIDI.sendControlChange(cc11, cc_on, 3);
  }
   if (button12.fallingEdge())
  {
    usbMIDI.sendControlChange(cc12, cc_on, 3);
  }
  if (button13.fallingEdge())
  {
    usbMIDI.sendControlChange(cc13, cc_on, 3);
  }
   if (button14.fallingEdge())
  {
    usbMIDI.sendControlChange(cc14, cc_on, 3);
  }
  if (button15.fallingEdge())
  {
    usbMIDI.sendControlChange(cc15, cc_on, 3);
  }
  if (button16.fallingEdge())
  {
    usbMIDI.sendControlChange(cc16, cc_on, 3);
  }
  if (button17.fallingEdge())
  {
    usbMIDI.sendControlChange(cc17, cc_on, 3);
  }
  if (button18.fallingEdge())
  {
    usbMIDI.sendControlChange(cc18, cc_on, 3);
  }
  if (button19.fallingEdge())
  {
    usbMIDI.sendControlChange(cc19, cc_on, 3);
  }
  if (button20.fallingEdge())
  {
    usbMIDI.sendControlChange(cc20, cc_on, 3);
  }
  if (button21.fallingEdge())
  {
    usbMIDI.sendControlChange(cc21, cc_on, 3);
  }
  if (button22.fallingEdge())
  {
    usbMIDI.sendControlChange(cc22, cc_on, 3);
  }
  if (button23.fallingEdge())
  {
    usbMIDI.sendControlChange(cc23, cc_on, 3);
  }
  if (button24.fallingEdge())
  {
    usbMIDI.sendControlChange(cc24, cc_on, 3);
  }
  if (button25.fallingEdge())
  {
    usbMIDI.sendControlChange(cc25, cc_on, 3);
  }
  if (button26.fallingEdge())
  {
    usbMIDI.sendControlChange(cc26, cc_on, 3);
  }
  if (button27.fallingEdge())
  {
    usbMIDI.sendControlChange(cc27, cc_on, 3);
  }

  

//(add more buttons here)   
//  if (button0.risingEdge())
//  {
//    usbMIDI.sendControlChange(cc0, cc_off, 3);
//  }
//  if (button1.risingEdge())
//  {
//    usbMIDI.sendControlChange(cc1, cc_off, 3);
//  }
//  if (button2.risingEdge())
//  {
//    usbMIDI.sendControlChange(cc2, cc_off, 3);
//  }
  if (button3.risingEdge())
  {
    usbMIDI.sendControlChange(cc3, cc_off, 3);
  }
  if (button4.risingEdge())
  {
    usbMIDI.sendControlChange(cc4, cc_off, 3);
  }
  if (button5.risingEdge())
  {
    usbMIDI.sendControlChange(cc5, cc_off, 3);
  }
  if (button6.risingEdge())
  {
    usbMIDI.sendControlChange(cc6, cc_off, 3);
  }
  if (button7.risingEdge())
  {
    usbMIDI.sendControlChange(cc7, cc_off, 3);
  }
  if (button8.risingEdge())
  {
    usbMIDI.sendControlChange(cc8, cc_off, 3);
  }
  if (button9.risingEdge())
  {
    usbMIDI.sendControlChange(cc9, cc_off, 3);
  }
  if (button10.risingEdge())
  {
    usbMIDI.sendControlChange(cc10, cc_off, 3);
  }
  if (button11.risingEdge())
  {
    usbMIDI.sendControlChange(cc11, cc_off, 3);
  }
  if (button12.risingEdge())
  {
    usbMIDI.sendControlChange(cc12, cc_off, 3);
  }
  if (button13.risingEdge())
  {
    usbMIDI.sendControlChange(cc13, cc_off, 3);
  }
  if (button14.risingEdge())
  {
    usbMIDI.sendControlChange(cc14, cc_off, 3);
  }
  if (button15.risingEdge())
  {
    usbMIDI.sendControlChange(cc15, cc_off, 3);
  }
  if (button16.risingEdge())
  {
    usbMIDI.sendControlChange(cc16, cc_off, 3);
  }
  if (button17.risingEdge())
  {
    usbMIDI.sendControlChange(cc17, cc_off, 3);
  }
  if (button18.risingEdge())
  {
    usbMIDI.sendControlChange(cc18, cc_off, 3);
  }
  if (button19.risingEdge())
  {
    usbMIDI.sendControlChange(cc19, cc_off, 3);
  }
  if (button20.risingEdge())
  {
    usbMIDI.sendControlChange(cc20, cc_off, 3);
  }
  if (button21.risingEdge())
  {
    usbMIDI.sendControlChange(cc21, cc_off, 3);
  }
  if (button22.risingEdge())
  {
    usbMIDI.sendControlChange(cc22, cc_off, 3);
  }
  if (button23.risingEdge())
  {
    usbMIDI.sendControlChange(cc23, cc_off, 3);
  }
  if (button24.risingEdge())
  {
    usbMIDI.sendControlChange(cc24, cc_off, 3);
  }
  if (button25.risingEdge())
  {
    usbMIDI.sendControlChange(cc25, cc_off, 3);
  }
  if (button26.risingEdge())
  {
    usbMIDI.sendControlChange(cc26, cc_off, 3);
  }
  if (button27.risingEdge())
  {
    usbMIDI.sendControlChange(cc27, cc_off, 3);
  }


}

Some of this code is pieced together since I don't know this coding language at all.
 
Last edited:
Before talking about details, the path to success for a large project is building and testing each small piece. If you create a huge untested program, it's extremely difficult to troubleshoot when something doesn't work, but none of the individual parts are well tested. When you've tested the smaller parts separately, you're working on a much better foundation that makes everything easier when you put it together. I know this may be overly obvious advice, but time and time again we see big MIDI controller projects get stalled because tons of untested stuff was cobbled together and then it's too hard to figure out which parts aren't working.

Now, some details. First, this part isn't right.

Code:
// 74HC4051 chip
switch (chipselect) {
    case 0:
      // pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 1:
         pinMode(4, OUTPUT);
      // pinMode(5, OUTPUT);
      // pinMode(7, OUTPUT);
      chipselect = chipselect + 1
      break;
    case 2:

You need to use pinMode() just once in setup. All 3 select pins are configured to OUTPUT mode and remain that way.

In loop(), you use digitalWrite to control which ones are LOW and which are HIGH. Your code doesn't have any digitalWrite anywhere. All 3 pins will remain LOW forever, so you're only going to read the first signal. The other 7 will never be used.


Second problem is this use of delay().

Code:
  // loop trough active inputs for knobs
  for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
      // calc the CC value based on the raw value
      ccValue[i] = inputAnalog[i]/8;
      // send the MIDI
      usbMIDI.sendControlChange(i, ccValue[i], 3);
      // set raw reading to lagged array for next comparison
      iAlag[i] = inputAnalog[i];
    }
  delay(5); // limits MIDI messages to reasonable number
  }

Because analogInputs is 8, this code will delay for a total of 40 ms. That's not terrible, but it definitely will make scanning everything else much slower. You really need to avoid using delay() when you have a big loop that checks multiple things.
 
I have tested most of the parts of this as I went a long the only 2 parts that are not fully tested are the encoder and the 74HC4051 chips. I just need to figure out how to get the encoders to make the scratch wheels work I.E. get the encoders to send midi commands. The 74HC4051 chip chunk of code was just throw together as a jumping off point to figure out if it will work or not. Thanks to you I now know it wont. It will need more code then what I have so far. For the DELAY(). What you are saying is to remove the DELAY() part of the code and it would improve everything?
 
Last edited:
I have a library that does encoders, faders and buttons, allowing you to send whatever midi messages you like. it supports a max of 13 buttons, 4 faders and 4 encoders .... it is not coded up for use with a mux, but ... extending it to 25 [??] buttons would be easy. the 8 muxed buttons I don't know about since I've never used a mux, and like I said the library doesn't support it

A simple example using my library for 1 fader and 2 encoders:

Code:
#include myController // that the name of my library

Rotary encoder1 (4, 6); //a new encoder with left and right pins
Rotary encoder2 (5, 7);
Fader slider1 (A5, 4); // a new slider with an analog read pin, and "4" as the jitter-suppression setting

void setup() {

encoder1.SetHandleLeft(left1);
encoder1.SetHandleRight(right1);

encoder2.SetHandleLeft(left2);
encoder2.SetHandleRight(right2);

slider1.SetHandleIncrease(up);
slider1.SetHandleDecrease(down);
}

void loop() {
Rotary::ReadWrite; // Sets the polling of both the encoders in motion.  No need for delays.
Fader::ReadWrite;
}

/*callbacks in pseudocode*/

void left1 (void) {
lefta ++
if (lefta >=128) {lefta = 0;}
sendmidi (x,y,lefta);
}

void left2 (void) {
leftb ++
if (leftb >=128) {leftb = 0;}
sendmidi (x,y,leftb);
}

void right1 (void) {
righta ++
if (righta >= -1) {righta = 127;}
sendmidi (x,y,righta);
}

void right2 (void) {
rightb ++
if (rightb >= -1) {rightb = 127;}
sendmidi (x,y,rightb);
}

void up (int increase) {
sendmidi (x,y,increase / 8); //"increase" is the value the slider has been moved up to, between 0 -1023.
}

void down (int decrease) {
sendmidi (x,y,decrease / 8); //"decrease" is the value the slider has been moved down to, between 0 -1023.
}

here is the library page ... (the examples are still a work in progress).

hopefully this gives you some help. I don't know about muxes though, but I think it would be easy to adapt code for them...
 
Last edited:
I have a library that does encoders, faders and buttons, allowing you to send whatever midi messages you like. it supports a max of 13 buttons, 4 faders and 4 encoders .... it is not coded up for use with a mux, but ... extending it to 25 [??] buttons would be easy. the 8 muxed buttons I don't know about since I've never used a mux, and like I said the library doesn't support it

A simple example using my library for 1 fader and 2 encoders:

Code:
#include myController // that the name of my library

Rotary encoder1 (4, 6); //a new encoder with left and right pins
Rotary encoder2 (5, 7);
Fader slider1 (A5, 4); // a new slider with an analog read pin, and "4" as the jitter-suppression setting

void setup() {

encoder1.SetHandleLeft(left1);
encoder1.SetHandleRight(right1);

encoder2.SetHandleLeft(left2);
encoder2.SetHandleRight(right2);

slider1.SetHandleIncrease(up);
slider1.SetHandleDecrease(down);
}

void loop() {
Rotary::ReadWrite; // Sets the polling of both the encoders in motion.  No need for delays.
Fader::ReadWrite;
}

/*callbacks in pseudocode*/

void left1 (void) {
lefta ++
if (lefta >=128) {lefta = 0;}
sendmidi (x,y,lefta);
}

void left2 (void) {
leftb ++
if (leftb >=128) {leftb = 0;}
sendmidi (x,y,leftb);
}

void right1 (void) {
righta ++
if (righta >= -1) {righta = 127;}
sendmidi (x,y,righta);
}

void right2 (void) {
rightb ++
if (rightb >= -1) {rightb = 127;}
sendmidi (x,y,rightb);
}

void up (int increase) {
sendmidi (x,y,increase / 8); //"increase" is the value the slider has been moved up to, between 0 -1023.
}

void down (int decrease) {
sendmidi (x,y,decrease / 8); //"decrease" is the value the slider has been moved down to, between 0 -1023.
}

here is the library page ... (the examples are still a work in progress).

hopefully this gives you some help. I don't know about muxes though, but I think it would be easy to adapt code for them...



Is the code you posted just for encoders.
 
I have a library that does encoders, faders and buttons, allowing you to send whatever midi messages you like. it supports a max of 13 buttons, 4 faders and 4 encoders .... it is not coded up for use with a mux, but ... extending it to 25 [??] buttons would be easy. the 8 muxed buttons I don't know about since I've never used a mux, and like I said the library doesn't support it

A simple example using my library for 1 fader and 2 encoders:

Code:
#include myController // that the name of my library

Rotary encoder1 (4, 6); //a new encoder with left and right pins
Rotary encoder2 (5, 7);
Fader slider1 (A5, 4); // a new slider with an analog read pin, and "4" as the jitter-suppression setting

void setup() {

encoder1.SetHandleLeft(left1);
encoder1.SetHandleRight(right1);

encoder2.SetHandleLeft(left2);
encoder2.SetHandleRight(right2);

slider1.SetHandleIncrease(up);
slider1.SetHandleDecrease(down);
}

void loop() {
Rotary::ReadWrite; // Sets the polling of both the encoders in motion.  No need for delays.
Fader::ReadWrite;
}

/*callbacks in pseudocode*/

void left1 (void) {
lefta ++
if (lefta >=128) {lefta = 0;}
sendmidi (x,y,lefta);
}

void left2 (void) {
leftb ++
if (leftb >=128) {leftb = 0;}
sendmidi (x,y,leftb);
}

void right1 (void) {
righta ++
if (righta >= -1) {righta = 127;}
sendmidi (x,y,righta);
}

void right2 (void) {
rightb ++
if (rightb >= -1) {rightb = 127;}
sendmidi (x,y,rightb);
}

void up (int increase) {
sendmidi (x,y,increase / 8); //"increase" is the value the slider has been moved up to, between 0 -1023.
}

void down (int decrease) {
sendmidi (x,y,decrease / 8); //"decrease" is the value the slider has been moved down to, between 0 -1023.
}

here is the library page ... (the examples are still a work in progress).

hopefully this gives you some help. I don't know about muxes though, but I think it would be easy to adapt code for them...


Well that code wont help do to it being for a Teensy 3.2 and I'm working with a Teensy 2.0 ++ for more pins.
 
Well that code wont help do to it being for a Teensy 3.2 and I'm working with a Teensy 2.0 ++ for more pins.

ah... but you can adapt it, I'm sure ... it is for encoders and faders and buttons. I thought maybe the techniques would be useful if nothing else.
 
I'm using Arduino actually and for reference the T2++ as you call it can use both Arduino and c programming languages.
 
I'm using Arduino actually and for reference the T2++ as you call it can use both Arduino and c programming languages.

So in the arduino IDE you use the T2++ board from the dropdown menu, when you compile?

I'll give that a try with my library and see what errors it throws up (the example above uses pseudo code for the midi messages send, so it would never work anyway .... what messages do you want to send with the rotaries and slider?).
 
To answer your question yes I'm using the Arduino software to program in and yes to the second part of your question. I'm using the Teensy 2.0 ++ from the drop down menu.

Mostly right now encoders so rotaries I guess. Its for the scratching desks. The program will be getting which way they are spinning. When I have it running in the serial monitor it displays which way its spinning + or - a number. I have no clue how to turn those numbers into something a MIDI program can read and have it zero out when it hasn't been touch for 0.5- 1 seconds of use or something like that.

The encoders I'm using for this project are out of a cheep mouse from china. They use them as the scroll wheel for the mouse. The encoder that is inside of the dj gear before this modding wouldn't pick up the fact I'm moving the scratch wheel when it was hooked to the Teensy.

If this does not make things clear tell me.
 
I had a look at you code... it does indeed look like you have cut and pasted bits from around the place. Could I suggest you get a few buttons and encoders and faders all working transmitting midi .... if you have already done that, then good. taking things slowly and testing each thing then moving on to the next ... compiling as it were all the bits into a whole. Honing your c/c++ is kind of a must obviously ... to that endm here is a zip of my library, modified for the T++2, and below is an example of 2 rotaries and 6 buttons and 1 fader.. the buttons spit out noteon noteoff, the fader does pitchbend, and the rotaries do CC 1 (modulation)... I'm not familiar with the t++2 pins so you can put them in yourself ... if you want many more buttons, you can modify my code with your own constructor and callbacks etc. for the Switches class. you could probably quite easily write a method for muxes as well. Indeed I am quite keen to try that out myself. Good luck!

View attachment 7521

Code:
#include <myController.h> // that the name of my library

/*I have no idea about the t2++ pins, so I have just put random ones in ...*/

Rotary encoder1 (4, 6); //a new encoder with left and right pins
Rotary encoder2 (5, 7);
Fader slider1 (A5, 4); // a new slider with an analog read pin, and "4" as the jitter-suppression setting
Switches Buttons ( 8, 9, 10, 11, 12, 13); // pins for buttons ... note 8 is button 1, 9 is button 2.
int rotary1mod = 0;
int rotary2mod = 0;
int pitch = 0;

void setup() {
  encoder1.SetHandleLeft(left1);
  encoder1.SetHandleRight(right1);

  encoder2.SetHandleLeft(left2);
  encoder2.SetHandleRight(right2);

  slider1.SetHandleIncrease(up);
  slider1.SetHandleDecrease(down);

  Buttons.SetHandleB1ON (but1ON);
  Buttons.SetHandleB1OFF (but1OFF);
  Buttons.SetHandleB2ON (but1ON);
  Buttons.SetHandleB2OFF (but2OFF);
  Buttons.SetHandleB3ON (but3ON);
  Buttons.SetHandleB3OFF (but3OFF);
  Buttons.SetHandleB4ON (but4ON);
  Buttons.SetHandleB4OFF (but4OFF);
  Buttons.SetHandleB5ON (but5ON);
  Buttons.SetHandleB5OFF (but5OFF);
  Buttons.SetHandleB6ON (but6ON);
  Buttons.SetHandleB6OFF (but6OFF);
}

void loop() {
  Rotary::ReadWrite(); // Sets the polling of both the encoders in motion.  No need for delays.
  Fader::ReadWrite();
  Switches::ReadWrite();
}

/*callbacks in pseudocode*/

void left1 (void) {
  rotary1mod ++;
  if (rotary1mod >= 128) {
    rotary1mod = 0;
  }
  usbMIDI.sendControlChange (1, rotary1mod, 1);
}

void left2 (void) {
  rotary2mod ++;
  if (rotary2mod >= 128) {
    rotary2mod = 0;
  }
  usbMIDI.sendControlChange (1, rotary2mod, 1);
}

void right1 (void) {
  rotary1mod --;
  if (rotary1mod >= -1) {
    rotary1mod = 127;
  }
  usbMIDI.sendControlChange (1, rotary1mod, 1);
}

void right2 (void) {
  rotary2mod --;
  if (rotary2mod >= -1) {
    rotary2mod = 127;
  }
  usbMIDI.sendControlChange (1, rotary2mod, 1);
}

void up (int increase) {
  pitch = map (increase, 0, 1023, -8191, 8192);
  usbMIDI.sendPitchBend (pitch, 1);
  //"increase" is the value the slider has been moved up to, between 0 -1023.
}

void down (int decrease) {
  pitch = map (decrease, 0, 1023, -8191, 8192);
  usbMIDI.sendPitchBend (pitch, 1);
  //"decrease" is the value the slider has been moved down to, between 0 -1023.
}

void but1ON(void) {
  usbMIDI.sendNoteOn (64, 127, 1);
}
void but2ON(void) {
  usbMIDI.sendNoteOn (65, 127, 1);
}
void but3ON(void) {
  usbMIDI.sendNoteOn (66, 127, 1);
}
void but4ON(void) {
  usbMIDI.sendNoteOn (67, 127, 1);
}
void but5ON(void) {
  usbMIDI.sendNoteOn (68, 127, 1);
}
void but6ON(void) {
  usbMIDI.sendNoteOn (69, 127, 1);
}
void but1OFF(void) {
  usbMIDI.sendNoteOff (64, 127, 1);
}
void but2OFF(void) {
  usbMIDI.sendNoteOff (65, 127, 1);
}
void but3OFF(void) {
  usbMIDI.sendNoteOff (66, 127, 1);
}
void but4OFF(void) {
  usbMIDI.sendNoteOff (67, 127, 1);
}
void but5OFF(void) {
  usbMIDI.sendNoteOff (68, 127, 1);
}
void but6OFF(void) {
  usbMIDI.sendNoteOff (69, 127, 1);
}

You must of not read my post with my code as I said I have tested it as I went a long. I started this modding project just to get the buttons to work. Which worked so I moved on to the fader between desk A and desk B. Which worked then I found midi ports in a pile of parts I had so I wired them in and got them working with the code. The next things on my list are getting the last buttons to work with a mux and the encoders to work. Since we are mostly talking about encoders that is what I'm working on first.
 
Cool ... the code I've given you will work for encoders...like I said, if you have done it bit by bit then that is great .... well done!!
 
Status
Not open for further replies.
Back
Top