works: MIDI-IN: code + schematics

Hello!

I'm on a MIDI project and this topic was very useful, thanks!

I'm playing around with this code and don't get it working.
All I want is to have the led on when a note is on and the led off when the note is off (no polyphony).
Here is the code:

//variables setup
byte incomingByte;


int statusLed = 13;   // select the pin for the LED

//setup: declaring iputs and outputs and begin serial
void setup() {
  pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
  Serial.begin(31250);        //start serial with midi baudrate 31250 or 38400 for debugging
  digitalWrite(statusLed,LOW);  
}


void loop () {

 if (Serial.available() > 0) {

    incomingByte = Serial.read();
    // wait for as status-byte, channel 1, note on or off

    if (incomingByte== 144){ // note on
      digitalWrite(statusLed, HIGH);
    }
    
    else if (incomingByte== 128){ // note off
      digitalWrite(statusLed, LOW);
    }
 }

}

The problem is that my led goes on, but never off!
Any idea?

Thanks :slight_smile: