Midi and Arduino

Hello,

I use a midi breakout made by Sparkfun and an Diecimila.

I need to made a merger as follow
If on the Midi input there is either 40, 48, 56, 64, 72, 80 notes then Midi output note 0.

I’ve done this, and not working, but do not see why ! Any help would be great

Here is the code :

#include <MIDI.h>

void RelaisMerge(byte num) { 
  
  if ( num == 40 || num == 48 || num == 56 || num == 64 || num == 72 || num == 80 )
  {
      MIDI.sendNoteOn(0,127,1); 
  }
void loop() {
  
  if (MIDI.read()) { 
    
    switch(MIDI.getType()) 
    
    {
      		
    case NoteOn :                          
    RelaisMerge(MIDI.getData1());	
    ;
    break ;

    }
    
  }
}

Thank you for any help

DS

Before posting code, it's always a good idea to try to compile it. Your code does not even have matching numbers of { and }, not to mention the missing setup() function.

I've done this, and not working

What is it doing that you don't want, or not doing that you do want?

Why bother with a switch statement with just one case? A simple if test is faster and requires less overhead.

I miss the setup() function

Is this your complete code?
Does it compile?

Sorry for the code, here is the full one which of course compiles :

#include <MIDI.h>

void RelaisMerge(byte num) { 
  
  //1	
  if ( num == 40 || num == 48 || num == 56 || num == 64 || num == 72 || num == 80 )
  {
      MIDI.sendNoteOn(0,127,1); // 
  }
  
  //2
  if ( num == 41 || num == 49 || num == 57 || num == 65 || num == 73 || num == 81 )
  {
      MIDI.sendNoteOn(1,127,1); // 
  }
  
  //3
  if ( num == 42 || num == 50 || num == 58 || num == 66 || num == 74 || num == 82 )
  {
      MIDI.sendNoteOn(2,127,1); // 
  }
  
  //4
  if ( num == 43 || num == 51 || num == 59 || num == 67 || num == 75 || num == 83 )
  {
      MIDI.sendNoteOn(3,127,1); //
  }
  
  //5
  if ( num == 44 || num == 52 || num == 60 || num == 68 || num == 76 || num == 84 )
  {
      MIDI.sendNoteOn(4,127,1); 
  }
  
  //6
  if ( num == 45 || num == 53 || num == 61 || num == 69 || num == 77 )
  {
      MIDI.sendNoteOn(5,127,1); 
  }
  
  //7
  if ( num == 46 || num == 54 || num == 62 || num == 70 || num == 78 )
  {
      MIDI.sendNoteOn(6,127,1); // LASER1 Note 0
  }
  
  //8
  if ( num == 47 || num == 55 || num == 63 || num == 71 || num == 79 )
  {
      MIDI.sendNoteOn(7,127,1); // 
  }
}

void RelaisMergeOff(byte num) { 
  
  //1	
  if ( num != 40 || num != 48 || num != 56 || num != 64 || num != 72 || num != 80 )
  {
      MIDI.sendNoteOff(0,0,1); // 
  }
  
  //2
  if ( num != 41 || num != 49 || num != 57 || num != 65 || num != 73 || num != 81 )
  {
      MIDI.sendNoteOff(1,0,1); // 
  }
  
  //3
  if ( num == 42 || num == 50 || num == 58 || num == 66 || num == 74 || num == 82 )
  {
      MIDI.sendNoteOff(2,0,1); // 
  }
  
  //4
  if ( num == 43 || num == 51 || num == 59 || num == 67 || num == 75 || num == 83 )
  {
      MIDI.sendNoteOff(3,0,1); // 
  }
  
  //5
  if ( num == 44 || num == 52 || num == 60 || num == 68 || num == 76 || num == 84 )
  {
      MIDI.sendNoteOff(4,0,1); // 
  }
  
  //6
  if ( num == 45 || num == 53 || num == 61 || num == 69 || num == 77 )
  {
      MIDI.sendNoteOff(5,0,1); // 
  }
  
  //7
  if ( num == 46 || num == 54 || num == 62 || num == 70 || num == 78 )
  {
      MIDI.sendNoteOff(6,0,1); // 
  }
  
  //8
  if ( num == 47 || num == 55 || num == 63 || num == 71 || num == 79 )
  {
      MIDI.sendNoteOff(7,0,1); // 
  }
}
 

void setup() {
  
  //Launch MIDI 
  MIDI.begin();            	
				
  //Out Relais

  
}

void loop() {
  
  if (MIDI.read()) { 
    
    switch(MIDI.getType()) 
    
    {
      		
    case NoteOn :                          
    RelaisMerge(MIDI.getData1());	
    //RelaisMergeOff(MIDI.getData1());
    break ;
    
    case NoteOff :                          
    //RelaisMerge(MIDI.getData1());	
    RelaisMergeOff(MIDI.getData1());
    break;
    
    }
    
  }
}

Please answer all the questions that are asked.

What is it doing that you don't want, or not doing that you do want?

So what i want to achieve is map serie of note :

If I push note 40,48,56,64,72,80 i need that arduino output note 0 for any of this notes. I use a keyboard connected to the Midi In then The midi out is connected to a device

For the moment I've got 2 problems :

  • When i push for note 40 the arduino output note 0 but also note 40
  • The note off is not functionning, the note stay On

Any ideas ?

Update : Sometimes randomly the note is not outputed ! Test on 2 different board !