MIDI Piano


i attempting create midi controller arduino uno take inputs push buttons beneath giant piano keys , play different notes each button. using usb-midi converter purchased on amazon send serial data computer, , using ableton live interpret data , play notes. running issues, , not sure whether due code, or live software. live has trouble recognizing signals, , play 2 notes @ once when press 1 button. problem run notes transfer both when button pushed , released. ideally transmit when button pushed. can suggest improvements code, or perhaps suggest alternative ableton live? below code, , attached screenshot of midi signals computer receives when each key pressed.
code: [select]

const int switchpin = 5;  
const int switchpin1 = 9;
const int switchpin2 = 10;
const int ledpin = 13;    

// variables:
void setup() {
    pinmode(switchpin, input);
  pinmode(switchpin1, input);
  pinmode(ledpin, output);
 
  serial.begin(31250);
}
int keypush = 0;
int keypush1 = 0;
int keypush2 = 0;
int loopmaxoutput = 50;
void loop() {
    //key 1  
  //if key pressed, play note once
      if (digitalread(switchpin) == 1 && keypush == 0) {  
  //loop sends noteon function multiple times. when sent once, computer did not register it.
          for(int = 0; < loopmaxoutput; i++)
          {
            noteon(0x90, 40, 0x60);
          }
        keypush = 1;
     }  
    //key 2
     if (digitalread(switchpin1) == 1 && keypush1 == 0) {
     
       for(int = 0; < loopmaxoutput; i++)
       {
          noteon(0x90, 50, 0x60);
       }
        keypush1 = 1;
     }  
     //key 3
     if (digitalread(switchpin2) == 1 && keypush2 == 0) {

       for(int = 0; < loopmaxoutput; i++)
       {
           noteon(0x90, 60, 0x60);
        }
          keypush2 = 1;
     }
     if(digitalread(switchpin) == 0 && keypush == 1) {
        keypush = 0;
     }        
     if(digitalread(switchpin1) == 0 && keypush1 == 1) {
        keypush1 = 0;
     }        
     if(digitalread(switchpin2) == 0 && keypush2 == 1) {
        keypush2 = 0;
     }
  }
  void noteon(byte cmd, byte data1, byte  data2) {
  serial.write(cmd);
  serial.write(data1);
  serial.write(data2);
}


moderator edit: [code] ... [/code] tags added. (nick gammon)

how have wired usb / midi interface arduino? have got proper interface or rubbish resistor one?
you should send note once, don't try , compensate poor intermittent hardware software, won't work.
how have wired switches? using external pull resistors?

you need add bit of switch debounce sketch. 20ms delay after key down or detected should it.


Arduino Forum > Using Arduino > Audio > MIDI Piano


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial