Please assist me in optimizing my (beginner) code

Thank you for your patience PaulS :slight_smile:
I have problem with the syntax or i just implement it the wrong way (or probably both).

This is what i got now (but the problem is that it sends a note and immediately after a note off)

#include "Wire.h"
#include "BlinkM_funcs.h"
#include <MIDI.h>

byte blinkm_all = 0x00; 
byte incomingByte; 

boolean pushbutton_pressed = false;
boolean midiOffSent = false; 

const int number_of_pushpins = 16;
int pushbutton_state[number_of_pushpins];

byte leds[] = {9, 10, 11, 12, 13, 14, 15, 16 ,17, 18, 19, 20, 21, 22, 23, 24};  // array for the i2c addresses of my blinkm's
int pushbutton_pins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18, 19, 22};


void setup() {
   
   MIDI.begin(1);
   Serial.begin(57600); // temporary so i can use spikenzielabs.com serial to midi app
   
    BlinkM_begin();
    
    for(int i=0; i< number_of_pushpins; i++){
       pinMode(pushbutton_pins[i], INPUT);
    }
 
}

void loop() {
  
  for(int i=0; i< number_of_pushpins; i++){
       pushbutton_state[i] = digitalRead(pushbutton_pins[i]);
    }


  for(int i=0; i< number_of_pushpins; i++){
       if( pushbutton_state[i] == HIGH) {
         if(pushbutton_pressed == false){
           BlinkM_setRGB(leds[i],0x00,0x00,0xff); 
             MIDI.sendNoteOn(70,127,1); 
             midiOffSent = false; 
           pushbutton_pressed = true;        

          
         }
       }else if (!midiOffSent) {
          
          
            MIDI.sendNoteOff(70,127,1);
            midiOffSent = true;

       }
          else{
            BlinkM_setRGB(leds[i],0x00,0x00,0x00);
            pushbutton_pressed = false;
            
          }
    }
}