Here is a way to loop the code, it compiles but did not test.
Code:
int thresh;
struct Sensor{
const uint8_t pin; //analog sensor pin nr
uint8_t note; //sensor midi note
bool noteIsOn; //sensor status
};
const uint8_t sensor_nr = 8;
//define sensor pin_nr and midi_note
Sensor sensor[sensor_nr]{
{0, 60, false},
{1, 64, false},
{2, 67, false},
{3, 70, false},
{6, 71, false},
{7, 72, false},
{8, 73, false},
{9, 74, false}
};
void setup() {
thresh = 225;
}
void loop() {
for(uint8_t s = 0; s < sensor_nr; s++) {
if (sensor[s].noteIsOn == false) {
if (analogRead(sensor[s].pin) > thresh) {
usbMIDI.sendNoteOn(sensor[s].note, 100, 1);
sensor[s].noteIsOn = true;
}
} else {
if (analogRead(sensor[s].pin) < thresh) {
usbMIDI.sendNoteOff(sensor[s].note, 0, 1);
sensor[s].noteIsOn = false;
}
}
}
while (usbMIDI.read()) {}
delay(5);
}