Hi guys , I'm having some problems with the reading process of Midi packets with the MIDI.h library.
My goal is to send and receive midi data separately, and I managed to do it. But my problem is that when I receive data on Arduino, the Arduino send out the same data that had received, and I don't understand why.
If anyone have some ideas about how to stop the Arduino to send back the data, I will appreciate some tips. Thanks.
This is the codes I'm working on, that consist in sending out the values of 4 potentiometers and receiving 4 values for turning green or red 4 bicolor led.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
//------------------NUMBER OF CONTROLS------------------
byte nLeds = 4;
byte nButtons = 4;
byte nPots = 4;
int Pot[]{A7,A6,A5,A4};
int Button[]{4,5,10,11};
int LedG[]{2,6,8,12};
int LedR[]{3,7,9,13};
byte potLastState[4];
byte potCurrentState[4];
int i = 0;
/////////////////////////////////////////////
// Metro Variables
void setup() {
MIDI.begin(2);
MIDI.setHandleControlChange(MyHandleControlChange);
 for (int i; i<4; i++) {
  pinMode (Button[i],INPUT_PULLUP);
  pinMode (LedG[i],OUTPUT);
  pinMode (LedR[i],OUTPUT);
 }
}
void loop() {
Â
potUpdate();
MIDI.read();
}
void potUpdate() {
  potCurrentState[i] = map(analogRead(Pot[i]),1023,0,0,127);
 Â
  if (potCurrentState[i] > potLastState[i] + 1 || potCurrentState[i] + 1 < potLastState[i])
  {Â
   //digitalWrite(LedG[i],HIGH);
  Â
   MIDI.sendControlChange (i, potCurrentState[i], 1);
  Â
   potLastState[i] = potCurrentState[i];
  }
  //else digitalWrite(LedG[i],LOW);
  i++;
  if (i==4) i=0;
}
void MyHandleControlChange(byte channel, byte number, byte value) {
if (channel==2) {
  switch (number) {
   case 0:
    if (value<63) {digitalWrite(LedG[0],HIGH); digitalWrite(LedR[0],LOW);}
    else {digitalWrite(LedG[0],LOW); digitalWrite(LedR[0],HIGH);}
    break;
   case 1:
    if (value<63) {digitalWrite(LedG[1],HIGH); digitalWrite(LedR[1],LOW);}
    else {digitalWrite(LedG[1],LOW); digitalWrite(LedR[1],HIGH);}
    break;
   case 2:
    if (value<63) {digitalWrite(LedG[2],HIGH); digitalWrite(LedR[2],LOW);}
    else {digitalWrite(LedG[2],LOW); digitalWrite(LedR[2],HIGH);}
    break;
   case 3:
    if (value<63) {digitalWrite(LedG[3],HIGH); digitalWrite(LedR[3],LOW);}
    else {digitalWrite(LedG[3],LOW); digitalWrite(LedR[3],HIGH);}
    break;
}
}
else {};
}