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

Thread: Help making a modwheel-type MIDI controller with Teensy LC

  1. #1
    Junior Member
    Join Date
    Dec 2016
    Posts
    16

    Help making a modwheel-type MIDI controller with Teensy LC

    Hi folks! A few years ago, this forum was super helpful with this project I was working on, which was a guitar-mounted MIDI controller that used the Teensy LC. It turned out great (here's a video if you'd like to see it). Anyway, I'm hoping you folks could give me a little more guidance on this new project I'm working on, and I apologize in advance for such a noob question. I haven't actually opened up the enclosure and looked at the Teensy LC since I finished my last project, but my recollection is that there's a row of pins for keyboard-type control, and another row of pins for continuous control, like mod wheels. So I'd basically like to use my Teensy LC to work like a midi controller with a bunch of mod wheels -- as many as possible. I just wanted to know if this is possible, and also, perhaps someone could help me get started or point me to the right tutorial. I'm mainly wondering what the code would look like. I'm using Teensyduino on a Mac running macOS Mojave. Thanks!

    For those of you are curious, here's why I want to do this: I basically want to "trick" Ableton Live into thinking that I'm using mod wheels when I'm actually using buttons. This is a way for me to get around the fact that, when you use a MIDI keyboard as a remote controller in Live, it ignores "key up" data. So there's no way to set it up so that you can enable a track or device when you press down a key, and disable it when you release the key. However, you can set it up so that you can enable something when you turn a mod wheel up, and disable it when you turn the wheel back down. So if you just wired a push button to the pot in a mod wheel, it would do what I want and it would be just like Ableton is responding to "key up" data. Btw, if someone knows of a way to do this without having to build a special controller, please let me know! I haven't had any luck on Ableton's forums at all.

  2. #2
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,094
    You could do the mod wheel thing... A Teensy LC can support 10 continuous controllers without additional parts.

    But you should be able to program a button box to send whatever MIDI you need to at both the key press and release.

    It sounds like you just want latching... it's just a change to a couple lines of code.

    Edit... not latching, you're trying to avoid their forced latching, I think you just need to change from sending note on / off to CC messages with D2=127 / 0
    Last edited by oddson; 05-05-2019 at 01:32 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2016
    Posts
    16
    Perfect, thanks #oddson! Sound like I might not even need to make any changes to the way it's currently wired. Which raises one question: I'm looking at the tutorials, and it looks like I need to press that little button on the Teensy LC if I want to compile new code... is that right? Or is that just for the first time you set it up? My Teensy is currently inside an enclosure, so it won't be super easy to get to that button.

    Also, one other question: What file extension do these Teensydunio code files use? I'm trying to find the original code I used back in 2016, and I'm having a hell of a time finding it! Anyway, thanks again.

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,094
    I've rarely needed to press the button on a Teensy. It will normally accept a new sketch without it.

    Arduino and Teensyduino sketches use .ino

    It's already in an enclosure? What is connected to it?

    This code can be altered quickly to give the result you're after

    https://github.com/PaulStoffregen/Te...tton_Knobs.ino

    It's also in the examples that download with Teensyduino..

    Code:
    //************DIGITAL SECTION**************
    void getDigitalData(){
      for (int i=0;i<D_PINS;i++){
      digital[i].update();
        if (digital[i].fallingEdge()) {
          usbMIDI.sendControlChange(CCID[i], 127, channel);  
        }
        // Note Off messages when each button is released
        if (digital[i].risingEdge()) {
          usbMIDI.sendControlChange(CCID[i], 0, channel);  
        }
      }
    }
    These lines and the array name (notes to CCID) should be about all the required changes.

  5. #5
    Junior Member
    Join Date
    Dec 2016
    Posts
    16
    Awesome, thanks! It's in an enclosure with two quarter inch TRS jacks, which I'm using to connect it to these rocker switches I built. So it is currently sending midi note data for four pins: C, C#, D, and D#. I think eventually I'll open it up again and wire in more jacks so I have access to the rest of the pins, and then I'll use some of them to send notes and some to send continuous controller data. But for now, I'm just going to use it as is and just change the code to make the four buttons send 127 and 0 on button down/up instead of sending C, C#, D and D#.

  6. #6
    Junior Member
    Join Date
    Dec 2016
    Posts
    16
    I am thrilled to report that my first test sketch is working exactly as I'd hoped! I haven't yet wired up all the additional pins, so I just coded it so that that pins 1 and 2 send midi notes (for this midi-controlled plugin I'm using), and pins 3 and 4 send control changes to switch certain tracks on and off in Ableton Live. The only problem I had was that I couldn't figure out how to get the Teensy LC to execute the code without pressing that little button. But no biggie!

    Anyway, as soon as I get the pushbuttons and stuff that I ordered, I'm going to wire up all the rest of the pins to send control signals like 3 and 4. Here's my code, btw. It's mostly code I copied and pasted from #oddson and from the website examples:

    Code:
    #include <Bounce.h>  // Bounce library makes button change detection easy
    
    const int channel = 0; 
    const int CC3 = 14 ; // the CC message sent with button 3
    const int CC4 = 15 ; // the CC message sent with button 4
    
    Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
    Bounce button2 = Bounce(2, 5);  // which is appropriate for good quality mechanical pushbuttons
    Bounce button3 = Bounce(3, 5);  
    Bounce button4 = Bounce(4, 5);
    
    void setup() {
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
    }
    
    void loop() {
      button1.update();
      button2.update();
      button3.update();
      button4.update();
      
    // CC messages when each button is pressed
    if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button2.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      
      if (button3.fallingEdge()) {
      usbMIDI.sendControlChange(CC3, 127, channel);
      }
      if (button4.fallingEdge()) {
      usbMIDI.sendControlChange(CC4, 127, channel);
      }
      
    // CC messages when each button is released
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);
      }
      if (button2.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);
      }
    
      if (button3.risingEdge()) {
      usbMIDI.sendControlChange(CC3, 0, channel);
      }
      if (button4.risingEdge()) {
      usbMIDI.sendControlChange(CC4, 0, channel);
      }
    
    
      // MIDI Controllers should discard incoming MIDI messages.
      while (usbMIDI.read()) {
      }
    }
    Incidentally, I wired up those four pins a couple years ago, and I can't remember why I didn't use pin 0. I'm wondering if I knew of some reason not to use it, or if I was just trying to avoid a solder bridge. Anyway, thanks again!

Posting Permissions

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