strange midi message in Hairless Midi-Serial

Hello everybody,

I get a strange midi message in Hairless Midi-Serial.
I built a midi drum kit with 9 pads connected to a multiplexer with 16 channels. 8 pads work and give a correct midi message with a single hit on the respective pad (see attachment)
But pads, that are connected to the multiplexer on channel 9-16, output an incorrect midi message (the "note off" message is missing! See attachment). I use an Arduino UNO with a MUX74HC4067 multiplexer and 9 piezo sensors. The Fritzing setup is also in the appendix.
Does anyone have any idea why this might be?
Thank you in advance : )
I've already searched several forums and I just can't find a solution.
This is the code:

#include "MUX74HC4067.h"
#include <MIDI.h>

MUX74HC4067 mux(8, 9, 10, 11, 12);

#define NUMBER_OF_PADS 9
#define VELOCITY_ACTIVE 1
#define LOG_MAPPING 1
#define MIDI_CHANNEL 1
#define MIDI_MAX_VELOCITY 1024
#define MIDI_NOTE_ON 0b1001
#define MIDI_NOTE_OFF 0b1000

uint8_t padNote[NUMBER_OF_PADS] = {51, 41, 45, 38, 37, 46, 36, 39, 44};
uint16_t padCycles[NUMBER_OF_PADS] = {40, 40, 40, 40, 60, 40, 60, 60, 60};
uint16_t padThreshold[NUMBER_OF_PADS] = {1, 1, 1, 1, 1, 1, 10, 10, 10};
uint16_t padCurrentCycles[NUMBER_OF_PADS];
uint8_t activePad;

void setup()
{
  Serial.begin(38400);
  mux.signalPin(A0, INPUT, ANALOG);
}

void loop(){

/////////// Drum Pads ////////////////////////////////////////////////////////////
  
  for (uint8_t pin = 0; pin < NUMBER_OF_PADS; pin++) {
    uint16_t val = mux.read(pin);      
    if ((val > padThreshold[pin]) && (!padActive(pin))) {
      val = VELOCITY_ACTIVE ? velocityAlgorithm(val,LOG_MAPPING) : MIDI_MAX_VELOCITY;
      uint8_t note = padNote[pin];
      midi_tx_note_on(MIDI_CHANNEL, note, val);
      padCurrentCycles[pin] = 0;
      activePad |= 1 << pin;
    }
    if (padActive(pin)) {
      padCurrentCycles[pin] += 1;
      if (padCurrentCycles[pin] >= padCycles[pin]) {
          midi_tx_note_off(MIDI_CHANNEL, padNote[pin]);
          activePad &= ~(1 << pin);
      }
    }
  }
}

/////////// Velocity Algorithm ////////////////////////////////////////////////////////////

uint8_t velocityAlgorithm(uint16_t val, uint8_t logswitch) {
  if (logswitch) {
     return log(val + 1)/ log(1024) * 127;
  }
    return (val - 0) * (127 - 0) / (1023 - 0) + 0;
}
uint8_t padActive(uint8_t currentPin) {
  return (activePad >> currentPin) & 1;
}

/////////// MIDI Message //////////////////////////////////////////////////////////////////


void midi_tx_note_on(uint8_t channel, uint8_t pitch, uint8_t velocity) {
    channel += 0xB0 - 1;
  if (channel >= 0xB0 && channel <= 0xBF)
  Serial.write((MIDI_NOTE_ON << 4) | (MIDI_CHANNEL - 1));
  Serial.write(pitch);
  Serial.write(velocity);
}
void midi_tx_note_off(uint8_t channel, uint8_t pitch) {
    channel += 0xB0 - 1;
  if (channel >= 0xB0 && channel <= 0xBF)
  Serial.write((MIDI_NOTE_OFF << 4) | (MIDI_CHANNEL - 1));
  Serial.write(pitch);
  Serial.write(0);
}

right-Midi-Message.jpg

wrong-Midi-Message.jpg