simple and brilliant, thank you so much. Is the same possible for reading the different cables? Where do I have to insert the cable number? I want to read from two different MIDI Mashines (cable1 = X32 (Monitor Mute); cable2 = X-Touch (Recording Light)
Code:
int bzaehler = 0;
int x32 = 0; //MIDI Interface (0= Anschluss 1)
void setup() {
pinMode(11, OUTPUT); //Recording light
pinMode(12, OUTPUT); //Mute Light
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(2, !LOW); // relay module with optocoupler, inverted signal
digitalWrite(3, !LOW); // relay module with optocoupler, inverted signal
digitalWrite(4, !LOW); // relay module with optocoupler, inverted signal
digitalWrite(5, !LOW); // relay module with optocoupler, inverted signal
usbMIDI.setHandleNoteOn(onNoteOn) ;
usbMIDI.setHandleControlChange(onControlChange);
}
void loop() {
usbMIDI.read();
}
//Recording light
void onNoteOn(byte kanal, byte note, byte velocity) {
if ((kanal == 1) & (note == 95) & (velocity == 127)) {
digitalWrite(11,HIGH);
}
if ((kanal == 1) & (note == 93) & (velocity == 127)) {
digitalWrite(11,LOW);
}
}
// Monitor Mute On through Mute Buttons
void onControlChange(byte kanal, byte control, byte value) {
if ((bzaehler == 0) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
digitalWrite(12,HIGH);
digitalWrite(2,HIGH);
usbMIDI.sendProgramChange(0, 2, x32);
}
if ((kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
bzaehler++;
}
// Monitor Mute Off through Mute Buttons
if ((bzaehler == 1) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
digitalWrite(12,LOW);
digitalWrite(2,LOW);
usbMIDI.sendProgramChange(1, 2, x32);
}
if ((kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
bzaehler--;
}
}