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

Thread: Trouble sending midi notes.

  1. #1

    Trouble sending midi notes.

    PROBLEM SOLVED:

    Turns out it was this line of code:
    Code:
    pinMode(1, OUTPUT); //midi output pin


    Hey guys... again...
    I'm currently working on a project that will be a numbered keypad that sends out midi program changes. It will work like this:Hold a button down, then type in the program change number, then let go of held button, then each time button is short pressed send out the program change. I cant get the midi out put working. I have the jack wired as described here: https://www.pjrc.com/teensy/td_libs_MIDI.html. Here's the code I'm working with:


    Code:
    // include the library code:
    #include <LiquidCrystal.h>
    #include <Keypad.h>
    #include <OneButton.h>
    #include <MIDI.h>
    //#include <midi_Defs.h>
    
    
    // initialize the library by associating any needed LCD interface pin
    // with the arduino pin number it is connected to
    const int rs = 12, en = 11, DB4 = 10, DB5 = 9, DB6 = 8, DB7 = 7;
    LiquidCrystal lcd(rs, en, DB4, DB5, DB6, DB7);
    
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); 
    
    const byte ROWS = 4; //four rows
    const byte COLS = 3; //three columns
    char keys[ROWS][COLS] = {
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'#','0','*'}
    };
    byte rowPins[ROWS] = {16, 17, 18, 19}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {13, 14, 15}; //connect to the column pinouts of the keypad
    
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    
    // Setup a new OneButton on pin A6.  
    OneButton button1(A6, true);
    // Setup a new OneButton on pin A7.  
    OneButton button2(A7, true);
    
      char prognum1;
      char prognum2;
      char prognum3;
      int midiprogrom1; 
    
    
    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(20, 4);
      // Print a message to the LCD.
      lcd.print("hell yeah, world!");
      MIDI.begin(1);
    
      pinMode(1, OUTPUT); //midi output pin
     
      
      //pinMode(1, OUTPUT);
      //MIDI.begin(1); 
    
      // link the button 1 functions.
      button1.attachClick(click1);
      button1.attachDuringLongPress(longPress1);
      button1.attachLongPressStop(longPressStop1);
    
      // link the button 2 functions.
      button2.attachClick(click2);
      button2.attachDuringLongPress(longPress2);
      button2.attachLongPressStop(longPressStop2);
    
      Serial.begin(31250);
    
    }
    
    void loop() {
      // keep watching the push buttons:
      button1.tick();
      button2.tick();
    
      // You can implement other code in here or just wait a while 
      delay(10);
    }
    
    // This function will be called when the button1 was pressed 1 time (and no 2. button press followed).
    void click1() {
      Serial.println("midi program 1 button 1 sent");
      MIDI.sendProgramChange(midiprogrom1,1);
      
    } // click1
    
    // This function will be called often, while the button1 is pressed for a long time.
    void longPress1() {
      
    Serial.println("Waiting for key1");
      prognum1 = keypad.waitForKey();
      lcd.setCursor(1, 3);
      lcd.print(prognum1);
      Serial.println(prognum1);
      
    
      
    Serial.println("Waiting for key2");
      prognum2 = keypad.waitForKey();
      lcd.setCursor(2, 3);
      lcd.print(prognum2);
      Serial.println(prognum2);
    
    Serial.println("Waiting for key3");
      prognum3 = keypad.waitForKey();
      lcd.setCursor(3, 3);
      lcd.print(prognum3);
      Serial.println(prognum3);
      midiprogrom1= 100*(prognum1- '0') + 10*(prognum2- '0') + prognum3 - '0';
      Serial.println(midiprogrom1);
    } // longPress1
    
    
      
     // longPressStart1
    
    // This function will be called once, when the button1 is released after beeing pressed for a long time.
    void longPressStop1() {
      
      Serial.println("Button 1 longPress stop");
    
      Serial.println("midi program number =");
    
      Serial.println(midiprogrom1);
      
    } // longPressStop1
    
    
    
    // ... and the same for button 2:
    
    void click2() {
      Serial.println("Button 2 click.");
    } // click2
    
    
    // This function will be called often, while the button1 is pressed for a long time.
    void longPress2() {
      Serial.println("Button 1 longPress...");
    } // longPress1
    
    
    void longPressStop2() {
      Serial.println("Button 2 longPress stop");
    } // longPressStop2

    Basically after longpressing then typing in the number when i go to short press and send the midi program change nothing happens to the keyboard (late 80s casio) I'm sending midi to. I'm not seeing anything on the osciliscope besides a constant peak every 560hz or so on pin 1.
    Last edited by cfredisded; 02-01-2018 at 09:48 PM. Reason: FIxed issue

Posting Permissions

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