I need help with playing MIDI notes.

I am working on the project using capacitive sensors to trigger MIDI notes. I am able to play single notes no problem. But for my project I would like to play a sequence of 3-4 notes. Would it be possible to write this line to play the selection of 3 notes instead of all notes E 4; F 4; F# 4; G 4; G# 4; A 4(//PAD3////////). Could you tell me how?

for (int note = 0x40; note < 0x45; note ++)

The rest of the code is this

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);  //PAD1      
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);  //PAD2
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);  //PAD3


int sen = 100;//sensitivity of your pads
int noteON = 144;//144 = 10010000 in binary, note on command

void setup() {

  Serial.begin(31250); //  Set MIDI baud rate:

}

void loop() {

  long total1 =   cs_2_3.capacitiveSensor(30);
  long total2 =   cs_2_4.capacitiveSensor(30);
  long total3 =   cs_2_5.capacitiveSensor(30);
 

  //PAD1////////////////////////////

  static int lastInput1 = 0;
  int newInput1 = total1;
  if((lastInput1 < sen) && (newInput1 > sen)) {

    for (int note=50;note<51;note++) {//from note 50 (D3) to note 69 (A4)
      MIDImessage(noteON, note, 127); 
    }
  };//turn note on
  if((lastInput1 > sen) && (newInput1 < sen)) {
    for (int note=50;note<51;note++) {//from note 50 (D3) to note 69 (A4)
      MIDImessage(noteON, note, 0); 
    }
  };
  lastInput1 = newInput1;

  //PAD2///////////////////////

  static int lastInput2 = 0;
  int newInput2 = total2;
  if((lastInput2 < sen) && (newInput2 > sen)) {
    for (int note=52;note<53;note++) {//from note 50 (D3) to note 69 (A4)
      MIDImessage(noteON, note, 127); 
    }
  };//turn note on
  if((lastInput2 > sen) && (newInput2 < sen)) {
    for (int note=52;note<53;note++) {//from note 50 (D3) to note 69 (A4)
      MIDImessage(noteON, note, 0); 
    }
  };
  lastInput2 = newInput2;

  //PAD3////////////////////////////

  static int lastInput3 = 0;
  int newInput3 = total3;
  if((lastInput3 < sen) && (newInput3 > sen)) {

    for (int note = 0x40; note < 0x45; note ++) {
      MIDImessage(noteON, note, 127);
     delay(100); 
    }
  };//turn note on
  if((lastInput3 > sen) && (newInput3 < sen)) {
    for (int note = 0x40; note < 0x45; note ++) {
      MIDImessage(noteON, note, 0);
    
    }
  };
  lastInput3 = newInput3;





}
//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
}

maybe you could try to put the notes inside an array and then loop through the array (maybe with a for loop) when you need them played.

i would also suggest that you be coherent with how you write your notes and commands. If you decide to use hexadecimal numbers (like 0x40) then use it always, if you decide to use decimal (like 144) then keep to decimal. It is less confusing than having some numbers like this and some like that.
The MIDI protocol uses hexadecimal, so maybe that would be a nice choice! :wink:

a question for you?
When you send this message:

MIDImessage(noteON, note, 0)

are you trying to end the note? Wouldn't it be better to send a noteOff command (0x80)?

just one other thought...
as you may have seen on other threads here on the forum, people are often advised against using the delay() function.
This is really important when you are building an instrument.
What the delay() function makes, is kind of "pause" your sketch. That means that during the delay NOTHING else can happen, so you wouldn't be able for instance to play another note.
Maybe a better solution would be to use the technic from the BlinkWithoutDelay example (www.arduino.cc/en/Tutorial/BlinkWithoutDelay) which will allow you to "delay" a note (or something else) for de desired time, while still being able to run the sketch (maybe check for other notes played, send other commands,...)

good luck!
=)