This "should" work, but no...third bit is 0 but not coming through?

I'm sending this midi signal to turn an LED off: 144,60, 0

But my code doesn't seem to be catching the "0". If I change that value to a hard coded different number, it works. Is there something with the last bit being 0 that it gets dropped or something?

Here is my code:

int First = 0;
int Second = 0;
int Third = 0;

int Triggered = 126;
int Playing = 127;
int Looping = 1;
int Stopped = 0;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(57600);
  Serial.println("reset");
}

void loop() {
  
  if (Serial.available()>=3) {
  // now at least 3 bytes are in the buffer.
  First = Serial.read() ; 
  Second = Serial.read() ; 
  Third = Serial.read() ; 

  int bitToSet = Second - 60; //Set The output pin to the MIDI note number - 60.


   if (First == 144){
    
         if (Third == Stopped){
           registerWrite(bitToSet, LOW);
         }

         if (Third == Playing){
           registerWrite(bitToSet, HIGH);
         }
     
     }
   }


}
// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
// the bits you want to send
  static byte bitsToSend = 0;

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

}

THe LED lights up correctly, but doesn't go off. My MIDI monitor program is showing velocity of 127 for the LED to light, and velocity of 0 for note off...

I'm soooo close!!!! ]:D

  First = Serial.read() ; 
  Second = Serial.read() ; 
  Third = Serial.read() ;

Meaningful names really are important. If the 3rd value is velocity, the third value should be stored in a variable called Velocity or velocity, not Third.

Is there something with the last bit being 0 that it gets dropped or something?

No. Some sort of test driver would be very useful. A C# application (if you are using Windows) would be pretty easy to put together. You could have three test fields, for the three values (with appropriate labels, which I'm guessing are NOT first, second, and third), and a Send button.

When the Send button is pressed, send the three values as binary data. The Arduino could then echo the data it received, so you know that what was sent was what was received.

The C# application could show the echoed data in three more fields, or as debug output.

Or, adding an LCD screen would give you another way to display data.

Or, turn the on-board LED on or off, based on whether Third is 0 or not, which will tell you whether the problem is with receiving the incoming MIDI data or with what you are doing with that data.

I don’t know what you mean by “midi signal.” Are the 3 values being sent as bytes or are you sending them as ASCII (through the Serial Monitor)?

Meaningful names really are important.

Point taken. They should be:

  midiMessage = Serial.read() ; 
  noteNumber = Serial.read() ; 
  Velocity = Serial.read() ;

and in fact that simple advice just made me realize that I had been thinking of the first bit wrong-MIDI note off should be 128 while note on is 144.

So it should be:

 if (First == 144){
    
       

         if (Third == Playing){
           registerWrite(bitToSet, HIGH);
         }
     
     }
     if (First == 128){
    
         if (Third == Stopped){
           registerWrite(bitToSet, LOW);
         }
     
     }

Thanks again-you really pointed me in the right direction! On to the next step!!

@James-They are being sent through the Serial to MIDI converter. Unfortunately, you can't send the full midi message through the Serial Monitor (as I just learned in the question I asked here only 30 minutes ago or so...) :D

BTW-I too am in ATX 8)