Teensyduino - Page 2
Page 2 of 7 FirstFirst 123456 ... LastLast
Results 11 to 20 of 68

Thread: Teensyduino

  1. #11

    Default

    Some of the pins are sending 2 different notes one when I press it down and a different when I release. While pin 6 isn't working at all, but I think I just need to add an external pull down cause if the led. Also I'm having a hard time getting analog to work. If it helps I have the buttons hooked up to pins 3-14 for the digital inputs.

  2. #12
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    Without knowing any of the potential differences between an arduino and a teensy, the following should be all you need to make the code work with the usbmidi of the teensy (side note, I am LOVING how he deals with the analog inputs... very clever, I'm certainly going to poke around to fully understand things)...

    I cannot see any reason why the code wouldn't work as is with the teensy... did you make sure you have all the pin assignments correct?

    Code:
    void noteOn(int channel, int pitch, int velocity)
    {
      // 0x90 is the first of 16 note on channels. Subtract one to go from MIDI's 1-16 channels to 0-15
      channel += 0x90 - 1;
      
      // Ensure we're between channels 1 and 16 for a note on message
      if (channel >= 0x90 && channel <= 0x9F)
      {
        #ifdef DEBUG
          Serial.print("Button pressed: ");
          Serial.println(pitch);
        #else
          usbMIDI.sendNoteOn(pitch, velocity, channel)
        #endif
      }
    }
    
    // Send a MIDI note off message
    void noteOff(int channel, int pitch)
    {
      // 0x80 is the first of 16 note off channels. Subtract one to go from MIDI's 1-16 channels to 0-15
      channel += 0x80 - 1;
      
      // Ensure we're between channels 1 and 16 for a note off message
      if (channel >= 0x80 && channel <= 0x8F)
      {
        #ifdef DEBUG
          Serial.print("Button released: ");
          Serial.println(pitch);
        #else 
          usbMIDI.sendNoteOff(pitch, 0x00, channel)
        #endif
      }
    }
    
    // Send a MIDI control change message
    void controlChange(int channel, int control, int value)
    {
      // 0xB0 is the first of 16 control change channels. Subtract one to go from MIDI's 1-16 channels to 0-15
      channel += 0xB0 - 1;
      
      // Ensure we're between channels 1 and 16 for a CC message
      if (channel >= 0xB0 && channel <= 0xBF)
      {
        #ifdef DEBUG
          Serial.print(control - MIDI_CC);
          Serial.print(": ");
          Serial.println(value);
        #else
          usbMIDI.sendControlChange(control, value, channel)      
        #endif
      }
    }

  3. #13
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    Important question: Are you using the code in midifighter mode? In other words, what is the current state of the following code

    Code:
    // Uncomment this line to enable outputs corresponding to the MIDI Fighter so MF mappings can be used in Traktor.
    //#define MIDI_FIGHTER

  4. #14

    Default

    Thanks for the code I'll have to give it a shot in the morning. Where would that go in the existing code?

    I believe that all of my pin assignments are correct. I only found 2 spots where I had to change the pin numbers in the code. Is there somthing I should change for the analog?

  5. #15

    Default

    I left that commeted I'm not using it in midi fighter mode

  6. #16
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    Ok... so... from what I can see, you need to refer to the teensy pins by their constants (PIN_D0, PIN_C1, etc...) arduino just uses the numbers, 2, 3, 4, 5, etc... so at the top of the code you will have to change the DIGITAL_PIN_ORDER define to the correct values...

    Which you can find here: http://pjrc.com/teensy/td_digital.html

    Pay attention to the midi fighter section, if you want to use it, make sure you wire the buttons right, OR specify the buttons in the correct order for the MF part to send the right notes (it should work regardless, it'll just be sending the wrong notes compared to a MF)

    For the internal pullups, make sure you have the INPUT_PULLUP teensy extension is installed (no clue what the heck that is... never used a teensy before)..

    As for analogue, I'm not sure... I haven't read the analogue section of the teensy docs yet...

  7. #17
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    Quote Originally Posted by timcrawf88 View Post
    Thanks for the code I'll have to give it a shot in the morning. Where would that go in the existing code?

    I believe that all of my pin assignments are correct. I only found 2 spots where I had to change the pin numbers in the code. Is there somthing I should change for the analog?
    You'd replace the existing code block with what I posted... or to learn what I did, just compare the differences... All I did was add one line, and remove 3...

    Could you post a complete copy of YOUR code (make sure to use the # button to wrap it in [ code ] tags)

  8. #18
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    From what I can see of the analog part... there doesn't seem to be any difference between arduino and teensy... so just make sure your pin assignments are correct and it should work... if not, try to explain what exactly is happening with the analog part...

    But for now, leave them completely disconnected, focus on getting the buttons to work properly first..

  9. #19

    Default

    Code:
    // Number of digital inputs. Can be anywhere from 0 to 18.
    #define NUM_DI 12
    // Number of analogue inputs. Can be anywhere from 0 to 6.
    #define NUM_AI 6
    
    // Number of digital inputs. Can be anywhere from 0 to 68.
    //#define NUM_DI 52
    // Number of analogue inputs. Can be anywhere from 0 to 16.
    //#define NUM_AI 16
    
    #ifdef MIDI_FIGHTER
      #define MIDI_CHANNEL 3
      // First note, starting from lower left button
      #define NOTE NOTE_C2
      // When mapping to a MIDI Fighter we need to skip a row of buttons. Set this from 0-3 to define which row to skip.
      // Rows are ordered from bottom to top (same as the MIDI Fighter's button layout).
      #define SKIP_ROW 2
      // This pin order corresponds to the bottom left button being zero, increasing by one as we move from left to right, bottom to top
      // 8  9 10 11
      // 4  5  6  7
      // 0  1  2  3
      // This array size must match NUM_DI above.
      #define DIGITAL_PIN_ORDER 10, 11, 12, 13, 6, 7, 8, 9, 14, 3, 4, 5
    #else
      #define MIDI_CHANNEL 1
      // First note, starting from upper left button
      #define NOTE NOTE_C0
      // This pin order corresponds to the top left button being zero, increasing by one as we move from left to right, top to bottom
      // 0  1  2  3
      // 4  5  6  7
      // 8  9  10 11
      // This array size must match NUM_DI above.
      #define DIGITAL_PIN_ORDER 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
    //  #define DIGITAL_PIN_ORDER 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53
    #endif
    
    #define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5
    //#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
    #define MIDI_CC MIDI_CC_GENERAL1
    This is the only section that i changed (it wouldn't let me post the entire thing)

    not sure how to redefine the analog inputs in the code, but according to teensys website you can call the inputs PIN_D3 or pin 3 so theoretically it should work lol http://pjrc.com/teensy/teensyduino.html

    however i just noticed that i may have analog wrong does it look like 28-35 is the analog, or 38-45 are the analog

  10. #20
    Tech Mentor
    Join Date
    Feb 2011
    Location
    Southern Ontario, Canada
    Posts
    244

    Default

    Change:
    Code:
    #define DIGITAL_PIN_ORDER 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
    To:
    Code:
    #define DIGITAL_PIN_ORDER PIN_D0
    PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6, PIN_D7, PIN_E0, PIN_E1, PIN_C0, PIN_C1, PIN_C2, PIN_C3, PIN_C4

    Re: analog

    Teensy seems to use the same method for pin-naming as the arduino, so you would use the pin numbers you wired them up to as per this pic:


Page 2 of 7 FirstFirst 123456 ... 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
  •