I need help with math? or something else.

I have this code for playing MIDI notes when sensors are touched. Using SparkFun or Adafruit capsense MPR121 boards.
For now I got it for rather simple by adding number(like 48) to i for sending notes 48…59 and so on.
However I wish to skip some notes in order to play set sequence. Like 48;50; 51; 54 instead of 48;49;50;51…
How to modify this part to get it without setting note numbers for every sensor pin separate:

for (uint8_t i=0; i<12; i++) {
// it if is touched and wasnt touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
MIDI.sendNoteOn(i+48, 127, 1); //send note 48+i
}
// if it was touched and now isnt, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
MIDI.sendNoteOff(i+48, 0, 1);
}

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

#include <Wire.h>
#include "Adafruit_MPR121.h"

// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();


// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;

void setup() {
  Serial.begin(9600);
  MIDI.begin();

 
  
  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 
  
  // Default address is 0x5A, if tied to 3.3V its 0x5B
  // If tied to SDA its 0x5C and if SCL then 0x5D
   if (!cap2.begin(0x5C)); 
     if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
}

void loop() {
  // Get the currently touched pads
  currtouched = cap.touched();
  currtouched2 = cap2.touched();
  
  for (uint8_t i=0; i<12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
       MIDI.sendNoteOn(i+48, 127, 1); //send note 48+i
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
       MIDI.sendNoteOff(i+48, 0, 1);
    }
/////////////////////////////////////////////////////
    if ((currtouched2 & _BV(i)) && !(lasttouched2 & _BV(i)) ) {
       MIDI.sendNoteOn(i+60, 127, 1); //send note 60+i
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched2 & _BV(i)) && (lasttouched2 & _BV(i)) ) {
       MIDI.sendNoteOff(i+60, 0, 1);
    }
  }

  // reset our state
  lasttouched = currtouched;
  lasttouched2 = currtouched2;
 
  return;
}
 Like 48;50; 51; 54 instead of 48;49;50;51....

You could put the values to be output in an array or arrays and use the value of i as an index to them. How many different output sequences will there be and how many notes in them ?

Thanks!
This would be one way to go indeed. If I understand this: touching one sensor pin will trigger a sequence of notes with set interval.
However my goal right now is to assign single(unique) note value to each pin(i number). So instead of being able to play all the notes in given octave I want to play notes that make up some kind of harmonic scale. 12 notes will cover then more than one octave but that is OK.
I could do this by writing out every sensor pin number and assigning a note to it with MIDI.sendNoteOn(); but when I want to make changes there would difficult to navigate the code.
Or I could name the note numbers like a;b;c… so I would MIDI.sendNoteOn(a,127,1) and it would be easy to make changes at the setup stage. But I am not able to figure how to assign a function(MIDO.send) to single sensor readout.

An enumerated list might help as you could give the note names values and the array of notes could contain the note names.

enum notes
{
  a = 123,
  b = 87,
  c = 512,
  d = 65
};

int seq[] = {b, a, d, c};

void setup()
{
  Serial.begin(115200);
  for (int x = 0; x < 4; x++)
  {
    Serial.println(seq[x]);
  }
}

void loop()
{
}

i reads 0-1-2-3-4…11 right now. Could it be possible to come up with some math equation in my code where I get this: if i=0 then x=i+48, if i=1 then x=i+50; if i=2 then x=i+51… and use x in MIDI.sendNoteOn(x, 127, 1);?

What I am getting at is when un-skilled person is playing the instrument(this is a sound-art installation BTW) and hit would sound harmonic and pleasant still instead of cacophony.

How do you envisage the sequence of notes getting into the program ?

No,no.
There will be still just one note to every sensor pin. Only the notes are not from 48 to 59. Its
like playing pentatonic scale that sounds right(OK) any way you play. Or having 3 notes that make accord C-major - C,E,G then adding F,A,C2 and B,D and so on. That's what I was referring to as sequence C E F G A B D

May some kind of mapping is what I need?

I am lost as to what you want to do.

Is the for loop being used as an index to pins attached to sensors so that touching the sensor is detected and the associated note is played ? If so, then once a touch is detected the current index value can be used as the index to an array of note values.

If that is not what you want then please explain it in more detail.

First, I truly appreciate that you walk with me on this.

once a touch is detected the current index value can be used as the index to an array of note values.

Yes, but instead of array just one note.
I could do it like this by assigning desired note to each pin(touch pad).

 for (uint8_t i=0; i<12; i++) 
  
    //PAD0///////////////////////////////////////////
  {   
    if ((currtouched & _BV(0)) && !(lasttouched & _BV(0)) ) {
      MIDI.sendNoteOn(48, 127, 1);
    }
    if (!(currtouched & _BV(0)) && (lasttouched & _BV(0)) ) {
      MIDI.sendNoteOff(48, 0, 1);
    }
  }
    //PAD1//////////////////////////////////////////
    {
    
    if ((currtouched & _BV(1)) && !(lasttouched & _BV(1)) ) {
      MIDI.sendNoteOn(50, 127, 1);
    }   
    if (!(currtouched & _BV(1)) && (lasttouched & _BV(1)) ) {
      MIDI.sendNoteOff(50, 0, 1);
    }
  }
    //PAD2//////////////////////////////////////////PAD1
    {    
    if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) {
      MIDI.sendNoteOn(52, 127, 1);
    }   
    if (!(currtouched & _BV(2)) && (lasttouched & _BV(2)) ) {
      MIDI.sendNoteOff(52, 0, 1);
    }
  }

But it makes the navigation in the code difficult when I need to change note numbers. I shall have 48 pads at the final project. Since this idea to add pin number value i and value 48 to get notes from 48 to 59 is very minimal code writing I thought to name note number x and calculate its value for every i value. So I do not need to write the function out for every note. Something like this:

for (uint8_t i=0; i<12; i++) 

//calculation or mapping to find x
//x=48 when i=0; x=50 when i=1; x=51 when i=2........ 

{
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
       
       MIDI.sendNoteOn(x, 127, 1); //send note 44+i
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
       MIDI.sendNoteOff(x, 0, 1);
    }

Yes, but instead of array just one note.

I am not suggesting sending a series of notes from teh array, just the one corresponding to the input detected.

Some pseudo code to ponder on

inputPins[] = {7, 8, 9, 10}  //array of input pin numbers 
noteValues[] = {200, 300, 350, 420}  //array of corresponding note values
keyIndex = 0

start of loop()
  if inputPins[keyIndex] becomes touched
    send noteValue[keyIndex] to MIDI
  else if inputPins[keyIndex] becomes released
    send noteValue[keyIndex] turn off to MIDI
  end if
  increment keyIndex
  if keyIndex > 3 keyIndex = 0 
end of loop()

The note values could be derived from an enum as earlier in this thread so the noteValues array would be more readable and easier to maintain as you could use the names for the notes instead of numeric values.

All right!!!
I see what you mean.
I hope to be able to make it work.

OK!
I came up with this and it works!!
Although I am not able to explain why entirely. Maybe

for (uint8_t i=0; i<12; i++)

creates an array(sequence) consecutive values i (0-11) and when use i as a pointer to my noteValue array I get notes correspond to the pin numbers i.

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

#include <Wire.h>
#include "Adafruit_MPR121.h"

Adafruit_MPR121 cap = Adafruit_MPR121();



// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;




int noteValue[] = {48, 52, 53, 55, 57, 59, 60, 64, 65, 67, 69, 71};  //array of corresponding note values


void setup() {
  Serial.begin(9600);
  MIDI.begin();

  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 
  
  // Default address is 0x5A, if tied to 3.3V its 0x5B
  // If tied to SDA its 0x5C and if SCL then 0x5D
    
     if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
}

void loop() {
  // Get the currently touched pads
  currtouched = cap.touched();
  
  
  for (uint8_t i=0; i<12; i++) {  // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
     
       MIDI.sendNoteOn(noteValue[i], 127, 1); //send note 44+i
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
       MIDI.sendNoteOff(noteValue[i], 0, 1);
    }
  }

  // reset our state
  lasttouched = currtouched;
  
  return;
}
}