Sticky Midi notes help me turn them off ! T_T

hi,
I have a little midi piano that connects to a computer by usb,
in ableton live for midi testing it is continuously playing notes , (even when not asked..)
something wrong with the note off?
can someone help me pinpoint what is causing this?
thanks

midiEventPacket_t noteOff = {0x08, 0x80 | Channel, lastNote, Velocity};
      MidiUSB.sendMIDI(noteOff);
      MidiUSB.flush();

      midiEventPacket_t noteOn = {0x09, 0x90 | Channel, Note, Velocity};
      MidiUSB.sendMIDI(noteOn);
      MidiUSB.flush();
      this->lastNote = this->Note;
      this->PlayingNote = 4;
      break;
    case 4:
      Tempo = this->Tempo;
      if (this->Timer > Tempo) {
        this->PlayingNote = 0;

        midiEventPacket_t noteOff = {0x08, 0x80 | Channel, Note, Velocity};
        MidiUSB.sendMIDI(noteOff);
        MidiUSB.flush();
      }
      break;
  }
}

uint8_t PlayNotes::MIDINoteAssignment(uint8_t StepSequence, uint8_t MIDINoteNumber, unsigned int Tempo) {
  uint8_t encoderReading;

  if (!digitalRead(encoderSW)) {
    //saveProgramChanged();
    return 128;
  }

  if (encoderReading = encoderRead()) {
    switch (encoderReading) {
      case encoderCW:
        if (MIDINoteNumber >= MIDINoteMax)
          MIDINoteNumber = MIDINoteMin;
        else
          MIDINoteNumber++;

        playNote1.PlayMIDINote(MIDINoteNumber, Tempo, NoteVelocity);                        ///////////////////////////////////CHECAR
        //saveProgramChanged();
        break;

      case encoderCCW:
        if (MIDINoteNumber <= MIDINoteMin)
          MIDINoteNumber = MIDINoteMax;
        else
          MIDINoteNumber--;

        playNote1.PlayMIDINote(MIDINoteNumber, Tempo, NoteVelocity);                        ///////////////////////////////////CHECAR
        //saveProgramChanged();
        break;

      case encoderUnchanged:
        break;
    }
  }

  return MIDINoteNumber;
}

uint8_t PlayNotes::keyAssignment(uint8_t StepSequence, uint8_t keyNumber, unsigned int Tempo) {
  uint8_t encoderReading;

  if (!digitalRead(encoderSW)) {
    //saveProgramChanged();
    return 0;
  }

  if (encoderReading = encoderRead()) {
    switch (encoderReading) {
      case encoderCW:
        if (numsOnly) {                                         //Only numbers mode
          if (keyNumber >= 10)
            keyNumber = 1;
          else
            keyNumber++;
        } else {                                         //Only numbers mode
          if (keyNumber >= sizeof(Keys) - 1)
            keyNumber = 1;
          else
            keyNumber++;
        }

        playNote1.PlayNote(keyNumber, Tempo);                        ///////////////////////////////////CHECAR
        //saveProgramChanged();
        break;

      case encoderCCW:
        if (numsOnly) {
          if (keyNumber <= 1)
            keyNumber = 10;
          else
            keyNumber--;
        } else {
          if (keyNumber <= 1)
            keyNumber = sizeof(Keys) - 1;
          else
            keyNumber--;
        }
        playNote1.PlayNote(keyNumber, Tempo);                        ///////////////////////////////////CHECAR
        //saveProgramChanged();
        break;

      case encoderUnchanged:
        break;
    }
  }

  return keyNumber;
}

Can you post a complete program that illustrates something you think should work but doesn't?

Perhaps not your entire sketch, a different complete sketch. Something we can work with.

With no context the partial code you have provided is no enough to go on.

TIA

a7