Help with midi controller transpose button

i tried to do this at final part to transpose 1 semitones but when release the combination of buttons dont change the pitch :



void noteOn(int cmd, int pitch, int velocity) {

  int btn1 = digitalRead (13);
  
if (btn1 == 0 && pitch == 36){
pitch = pitch + 1;
}
if (btn1 == 1) {
    Serial.write(cmd);
    Serial.write(pitch);
    Serial.write(velocity);

 }
   }