Sending multiple MIDI notes simultaneously

Hi,

Complete novice when it comes to Arduino and programming. I picked up an Uno last Friday with a view to making some weird MIDI instruments and so far I’ve managed to get it to switch a note on with one button and hold that note until I turn it off with another button.

What I’ve been trying to figure out how to do is get it to play three notes simultaneously with one button and then hold them until I switch those notes off again with the same button.

The next step from there would be to map those chords to a pot, then a joystick etc etc.

Here’s the code I’m using. Any help would be massively massively appreciated because I have no knowledge of programming whatsoever and I’m finding the process really difficult and frustrating. Basically assume that I have the same level of intelligence as a 4 year old child and go from there!

#include <MIDI.h>
 int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
 int noteON = 144;//144 = 10010000 in binary, note on command
 int noteOFF = 128;
 int buttonBpin = 8;
 int buttonApin = 9;

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
  pinMode(buttonBpin, INPUT_PULLUP);
  pinMode(buttonApin, INPUT_PULLUP); 

}

void loop() 


{
   if (digitalRead(buttonApin) == LOW)
  for (int note =50;note=50;note++) {//note 50
    MIDImessage(noteON, note, velocity);//turn note on
    delay (200); //wait 200ms
    break; }

   if (digitalRead(buttonBpin) == LOW)
   for (int note =50;note=50;note++) {//note 50
    MIDImessage(noteOFF, note, 0); //turn note off
    delay (200); //wait 200ms
  break;} 
  
}

//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
  Serial.write(command);//send note on or note off command 
  Serial.write(MIDInote);//send pitch data
  Serial.write(MIDIvelocity);//send velocity data
}

For 3 notes, just skip the for loop.

  if (digitalRead(buttonApin) == LOW) {
    MIDImessage(noteON, 50, velocity);//turn note on
    MIDImessage(noteON, 51, velocity);//turn note on
    MIDImessage(noteON, 52, velocity);//turn note on
    delay(100);
  }

  if (digitalRead(buttonBpin) == LOW) {
    MIDImessage(noteOFF, 50, velocity);//turn note off
    MIDImessage(noteOFF, 51, velocity);//turn note off
    MIDImessage(noteOFF, 52, velocity);//turn note off
    delay(100);
  }

That's brilliant, thankyou so much.

Can anyone tell me how I can switch on the chord and turn it off again with the same button please?

Or have any idea on how I might be able to assign those chords to a range of values on a pot? So, say if the value from the pot is between 1 and 10 it would play chord X, with a value between 10 and 15 it would send the note off message, then between 15 and 25 it would play chord Y etc etc. Those wouldn't be the exact range values of course, it's MIDI so it'd be seven chords and seven dead zones over a range of 0-127. I'd also like to use push buttons to define the key of the chords but that's a few steps away yet obviously.

Sorry if I'm asking the wrong sort of questions or asking stupid questions, I really don't know anything about this.