Replicating a NanoKontrol using a teensy?
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default Replicating a NanoKontrol using a teensy?

    Has anyone ever tried this?

    I love the nanokontrol and like most I hate the way it is built/designed. I've seen many people on here use the Nanokontrol pcb to create great controllers with different switches and pots.

    I want to integrate the nanokontrol into an existing mixer/controller but the problem I'm having is that the nanokontrol pcb won't fit. Since I have very limited freespace inside the mixer the teensy can be the next best thing.

    The thing I really like about the Nanokontrol is the "Scene" button which is what I'm really trying to create with the teensy. I'm really aiming to have only 15-20 buttons and but each button to have 3-4 different uses by changing the "scene"

    Has anyone had any success in doing this? I'm still a super noob when programming the teensy (2.0++) with the arduino software. I've only successfully programmed all the digital Inputs and 2 potentiometers. But I would really like to minimize the amount buttons with the scene button.

    Any help, info, or references would be great! Thanks in advance

  2. #2

    Default

    If you already know how to read and write digital inputs, it shouldn't be that much trouble. Assuming you want 4 scenes and have 4 LEDs, one for each scene, create some global variables:

    Code:
    #define SCENES_COUNT 4
    
    const int buttonPin = 2;
    const int ledPins[SCENES_COUNT] = {7, 8, 9, 10};
    
    int scene = 0;
    Set inputs and outputs:

    Code:
    void setup()
    {
      pinMode(buttonPin, INPUT);
      
      for (int i = 0; i < SCENES_COUNT; i++)
      {
        pinMode(ledPins[i], OUTPUT);
      }
    }
    Then inside the loop, increment scene and enable corresponding LED:

    Code:
    void loop()
    {
      // If scene button is pressed
      if (digitalRead(buttonPin) == HIGH)
      {
        // Increment scene by 1, and if it's greater than the scene count, reset to 0
        if (++scene >= SCENES_COUNT)
        {
          scene = 0;
        }
        
        // Loop through all LEDs
        for (int i = 0; i < SCENES_COUNT; i++)
        {
          // If i equals the current scene, enable this LED, otherwise disable it
          digitalWrite(ledPins[i], i == scene ? HIGH : LOW);
        }
      }
      
      switch (scene)
      {
        // First scene
        case 0:
          /* Read other buttons and do stuff here */
          break;
        // Second scene
        case 1:
          /* Read other buttons and do stuff here */
          break;
        // Third scene
        case 2:
          /* Read other buttons and do stuff here */
          break;
        // Fourth scene
        case 3:
          /* Read other buttons and do stuff here */
          break;
      }
    }
    Sorry if things like ++, ? :, for or switch are still new to you, I tried to explain them in the comments. It also doesn't anticipate contact bounce, not sure if that will be a problem.
    Last edited by ErikMinekus; 02-04-2013 at 05:43 PM.

  3. #3
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    Thanks friend!
    This is incredibly helpful! A couple more questions is you don't mind. Would the wiring be the same on the teensy board? Or would I be hooking up multiple teensy pins to a single switch? Would any additional hardware be needed?

  4. #4
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    Also I will be using Serato scratch live if that is any help

  5. #5
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    Sorry if I am being redundant but just wanted to clarify. For example: If I use the above code with four scenes, and since there are 46 inputs on the teensy 2.0+, does it mean it is possible to have 46x4 different inputs which is total 184 different inputs. As in using 46 buttons can control 184 different things on Serato? I know I will never use that many inputs but jus for the sake of the example.

  6. #6

    Default

    A button only uses one input, just like a regular LED only uses one output. Some other components have multiple inputs (slide switches) or outputs (LCDs, RGB LEDs). Even so, if you learn how to use shift registers you can connect dozens of inputs or outputs to one pin on the Teensy, in case you needed more than 46 pins.

    Next to that you can give buttons as many functions as you want from code, in my code you would just change SCENES_COUNT and add a new case-statement if you wanted more scenes. Look at it as a shift-button which most controllers have nowadays, where holding it gives the other buttons an entirely different function. If you want to send a unique note or CC for each button you're only limited to the MIDI protocol, which I believe supports 127 notes and 127 CCs per channel.

  7. #7
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    hey ErikMinekus so i finally had some free time today to fiddle around with the code you gave me but i haveing trouble compileing it.

    so i pre wrote this code( taken straight from the USB MIDI example) for 5 input buttons which was a successfull compile:

    Code:
          #include <Bounce.h>
    
    const int channel = 1;
    
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
    Bounce button2 = Bounce(2, 5);  // which is appropriate for good
    Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
    Bounce button4 = Bounce(4, 5);
    
    void setup() {
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
     }
     
     void loop() {
      button0.update();
      button1.update();
      button2.update();
      button3.update();
      button4.update();
      
      if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button2.fallingEdge()) {
        usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
      
      
      if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button2.risingEdge()) {
        usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
     }
    Now i just pasted it into the areas where u wrote "/* Read other buttons and do stuff here */". i tried making only 2 scenes just for testing so i ended up with this code:

    Code:
    #define SCENES_COUNT 2
    
    const int buttonPin = 2;
    const int ledPins[SCENES_COUNT] = {7, 8};
    
    int scene = 0;
    
    void setup()
    {
      pinMode(buttonPin, INPUT);
      
      for (int i = 0; i < SCENES_COUNT; i++)
      {
        pinMode(ledPins[i], OUTPUT);
      }
    }
    
    void loop()
    {
      // If scene button is pressed
      if (digitalRead(buttonPin) == HIGH)
      {
        // Increment scene by 1, and if it's greater than the scene count, reset to 0
        if (++scene >= SCENES_COUNT)
        {
          scene = 0;
        }
        
        // Loop through all LEDs
        for (int i = 0; i < SCENES_COUNT; i++)
        {
          // If i equals the current scene, enable this LED, otherwise disable it
          digitalWrite(ledPins[i], i == scene ? HIGH : LOW);
        }
      }
      
      switch (scene)
      {
        // First scene
        case 0:
          /* Read other buttons and do stuff here */
          #include <Bounce.h>
    
    const int channel = 1;
    
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
    Bounce button2 = Bounce(2, 5);  // which is appropriate for good
    Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
    Bounce button4 = Bounce(4, 5);
    
    void setup() {
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
     }
     
     void loop() {
      button0.update();
      button1.update();
      button2.update();
      button3.update();
      button4.update();
      
      if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button2.fallingEdge()) {
        usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
      
      
      if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button2.risingEdge()) {
        usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
     }
          break;
        // Second scene
        case 1:
          /* Read other buttons and do stuff here */
          #include <Bounce.h>
    
    const int channel = 1;
    
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
    Bounce button2 = Bounce(2, 5);  // which is appropriate for good
    Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
    Bounce button4 = Bounce(4, 5);
    
    void setup() {
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
     }
     
     void loop() {
      button0.update();
      button1.update();
      button2.update();
      button3.update();
      button4.update();
      
      if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button2.fallingEdge()) {
        usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
      
      
      if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button2.risingEdge()) {
        usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
     }
          break;
      }
    }
    it wont compile at all. sorry for being such a newb at all this trying to learn as much as possible before i post and ask questions. if you dont mind please look over the code and let me know where i made mistakes.

    thanks again for oyur help

  8. #8

    Default

    Yes, just pasting the entire code multiple times isn't going to work. I suggest you read some tutorials on basic C-programming and Arduino, so you at least understand variables and procedures. You can also find the similarities between my code and the USB MIDI example to see which parts you need to paste where.

  9. #9
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    Thanks ErikMinekus! I have a lot of arduino homework to do now. Haha I appreciate the help!

  10. #10
    Tech Convert
    Join Date
    Oct 2012
    Posts
    16

    Default

    hey ErikMinekus, so ive gone through all the tutorials on the link you posted and figured out why my code wouldnt compile. i had too many void loops and setups when there should only be one of each on this code so i ended up with this:

    Code:
    #define SCENES_COUNT 4
    #include <Bounce.h>
    const int channel = 1;
    
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
    Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
    Bounce button4 = Bounce(4, 5);
    
    const int buttonPin = 2;
    const int ledPins[SCENES_COUNT] = {7, 8, 9, 10};
    
    int scene = 0;
    
    void setup()
    {
      pinMode(buttonPin, INPUT);
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
      
      for (int i = 0; i < SCENES_COUNT; i++)
      {
        pinMode(ledPins[i], OUTPUT);
      }
    }
    
    
    
    void loop()
    {
      button0.update();
      button1.update();
      button3.update();
      button4.update();
      
      // If scene button is pressed
      if (digitalRead(buttonPin) == HIGH)
      {
        // Increment scene by 1, and if it's greater than the scene count, reset to 0
        if (++scene >= SCENES_COUNT)
        {
          scene = 0;
        }
        
        // Loop through all LEDs
        for (int i = 0; i < SCENES_COUNT; i++)
        {
          // If i equals the current scene, enable this LED, otherwise disable it
          digitalWrite(ledPins[i], i == scene ? HIGH : LOW);
        }
      }
      
      switch (scene)
      {
        // First scene
        case 0:
          /* Read other buttons and do stuff here */
           
           if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
      
      if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
      
          break;
        // Second scene
        case 1:
          /* Read other buttons and do stuff here */
           
           if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
            if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
    
          break;
        // Third scene
        case 2:
          /* Read other buttons and do stuff here */
           
           if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
            if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
      
          break;
        // Fourth scene
        case 3:
          /* Read other buttons and do stuff here */
          
           if (button0.fallingEdge()) {
        usbMIDI.sendNoteOn(60, 99, channel);  // 60 = C4
      }
      if (button1.fallingEdge()) {
        usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
      }
      if (button3.fallingEdge()) {
        usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
      }
      if (button4.fallingEdge()) {
        usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
      }
           if (button0.risingEdge()) {
        usbMIDI.sendNoteOff(60, 0, channel);  // 60 = C4
      }
      if (button1.risingEdge()) {
        usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
      }
      if (button3.risingEdge()) {
        usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
      }
      if (button4.risingEdge()) {
        usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
      }
      
          break;
      }
    }
    so ive gotten a successfull compile and able to use the midi push buttons but the scene button was still not working. i have push buttons connected to D0-D4 on my teensy 2++ and i programmed the d0,d1,d3,d4 as my midi buttons and left d2 for the scene button. should i have used different I/O's on the teensy board for each case?

    thanks for all your help by the way.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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