simple midi-in to turning an output-pin high

hello there, i have what i suppose is a real simple question, but it's driving me nuts.. i'm trying to get multiple output-pins high when i receive midi-notes simultanously. there are all kinds of midi libraries out there, but i can't find a working "polyphonic" solution.

very basic: note C (on) = pin 8 high note D (on) = pin 9 high note C (off) = pin 8 low ...etc

the crucial point is about receiving notes at the very same time. i've been using ableton as a sequencer and my arduino (more or less randomly) choses which of two simultanous notes he acts upon / sets a pin high.

any idea? i'd be gracious. benni

Can youpost the code you have sofar, it might be easier to comment on that

dunno what's the matter today.. i keep posting stuff in forums that suddenly works on its own :) so — it's working. don't bother, but thank you anyhow.

fyi:

/* Midi In Basic  0.2 // kuki 8.2007
 * 
 * ----------------- 
 * listen for midi serial data, and light leds for individual notes

 IMPORTANT:
 your arduino might not start if it receives data directly after a reset, because the bootloader thinks you want to uplad a new progam.
 you might need to unplug the midi-hardware until the board is running your program. that is when that statusLed turns on.

#####################################################################################################################################################
SOMETHING ABOUT MIDI MESSAGES
 midi messages start with one status byte followed by 1 _or_ 2 data bytes, depending on the command

 example midi message: 144-36-100
   the status byte "144" tells us what to do. "144" means "note on".
   in this case the second bytes tells us which note to play (36=middle C) 
   the third byte is the velocity for that note (that is how powerful the note was struck= 100)
   
 example midi message: 128-36
   this message is a "note off" message (status byte = 128). it is followed by the note (data byte = 36)
   since "note off" messages don't need a velocity value (it's just OFF) there will be no third byte in this case
   NOTE: some midi keyboards will never send a "note off" message, but rather a "note on with zero velocity"
  
 do a web search for midi messages to learn more about aftertouch, poly-pressure, midi time code, midi clock and more interesting things.
#####################################################################################################################################################

HARDWARE NOTE:
The Midi Socket is connected to arduino RX through an opto-isolator to invert the midi signal and seperate the circuits of individual instruments.
connect 8 leds to pin2-pin9 on your arduino.

####################################################################################################################################################
 */

//variables setup

byte incomingByte;
byte note;
byte velocity;

int BD = 8;
int SN = 9;
int HT = 10;
int MT = 11;
int LT = 12;

int action=2; //0 =note off ; 1=note on ; 2= nada


//setup: declaring iputs and outputs and begin serial 
void setup() {
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  
  //start serial with midi baudrate 31250 or 38400 for debugging
  Serial.begin(31250);        
}

//loop: wait for serial data, and interpret the message 
void loop () {
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    // wait for as status-byte, channel 16, note on or off
    
    if (incomingByte== 159){ // note on message starting starting
      action=1;
      
    }else if (incomingByte== 143){ // note off message starting
      action=0;
      
    }else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
      note=incomingByte;
      playNote(note, 0);
      note=0;
      velocity=0;
      action=2;
   
    }else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
      note=incomingByte;   
      
    }else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
      velocity=incomingByte;
      playNote(note, velocity);
      note=0;
      velocity=0;
      action=0;
    }else{
      //nada
    }
  }
}

void playNote(byte note, byte velocity){
  int value=LOW;
  if (velocity >0){
      value=HIGH;
  }else{
   value=LOW; 
  }

 //since we don't want to "play" all notes we wait for a note between 36 & 44
 if(note==36){
   digitalWrite(BD, value);
 } 

 else if (note==38){
   digitalWrite(SN, value);
 }

  else if (note==39){
   digitalWrite(HT, value);
 }

   else if (note==40){
   digitalWrite(MT, value);
 }

    else if (note==41){
   digitalWrite(LT, value);
 }

}

maybe the magic of the forum! or loose wires :wink:

Remember that MIDI is serial, it can not ever send two notes at the same time.

The other thing is that your code does cope with the sequencer sending you running status messages.