MIDI node sent on release instead of pression of a button

Hello everyone!

I'm trying to build a simple Arduino MIDI controller for my pc with just some buttons. The board I'm using is an Arduino UNO r3 and I'm using HIDUINO to interface it with the DAW I'm using on my pc.
Using the MIDI library this is the program I came up with:

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();


// read digital pins number 
int pushButton1 = 0;
int pushButton2 = 1;
int pushButton3 = 2;
int pushButton4 = 3;
int pushButton5 = 5;
int pushButton6 = 6;
int pushButton7 = 8;
int pushButton8 = 9;

//int changeButton = 12;

//int ledPin = 13;

 
// checks if the button is pressed
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;
int buttonState8 = 0;

//int buttonStateC = 0;
 
// play/stop notes in relation to buttons pressed
int note1 = 0;
int note2 = 0;
int note3 = 0;
int note4 = 0;
int note5 = 0;
int note6 = 0;
int note7 = 0;
int note8 = 0;

 
 

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
  pinMode(pushButton1, INPUT_PULLUP);
  pinMode(pushButton2, INPUT_PULLUP);
  pinMode(pushButton3, INPUT_PULLUP);
  pinMode(pushButton4, INPUT_PULLUP);
  pinMode(pushButton5, INPUT_PULLUP);
  pinMode(pushButton6, INPUT_PULLUP);
  pinMode(pushButton7, INPUT_PULLUP);
  pinMode(pushButton8, INPUT_PULLUP);
  
}
 
void loop() {
  // read state of buttons
  int buttonState1 = digitalRead(pushButton1);
  int buttonState2 = digitalRead(pushButton2);
  int buttonState3 = digitalRead(pushButton3);
  int buttonState4 = digitalRead(pushButton4);
  int buttonState5 = digitalRead(pushButton5);
  int buttonState6 = digitalRead(pushButton6);
  int buttonState7 = digitalRead(pushButton7);
  int buttonState8 = digitalRead(pushButton8);
 
  // Button 2
 
  // when button pressed:
  if (buttonState1 == HIGH) {
    // if note not playing
    if (note1 == 0) {
      // play note (note number, velocity, channel)
      // more info: http://arduinomidilib.sourceforge.net/a00001.html
      // MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
      // 55 = G3, 127 = trigger note with max volume
      MIDI.sendNoteOn(24,127,1);
      // note is playing
      note1 = 1;
    }
  // when button released
  } else {
    // if note playing
    if (note1 == 1) {
      // if playing - stop
      MIDI.sendNoteOff(24,0,1);
    }
    // if button released note is off
    note1 = 0;
  }
 
  
  if (buttonState2 == HIGH) {
    if (note2 == 0) {
      MIDI.sendNoteOn(25,127,1);
      note2 = 1;
    }
  } else {
    if (note2 == 1) {
      MIDI.sendNoteOff(25,0,1);
    }
    note2 = 0;
  }
 
 
  if (buttonState3 == HIGH) {
    if (note3 == 0) {
      MIDI.sendNoteOn(26,127,1);
      note3 = 1;
    }
  } else {
    if (note3 == 1) {
      MIDI.sendNoteOff(26,0,1);
    }
    note3 = 0;
  }

  
  if (buttonState4 == HIGH) {
    if (note4 == 0) {
      MIDI.sendNoteOn(27,127,1);
      note4 = 1;
    }
  } else {
    if (note4 == 1) {
      MIDI.sendNoteOff(27,0,1);
    }
    note4 = 0;
  }

  
  if (buttonState5 == HIGH) {
    if (note5 == 0) {
      MIDI.sendNoteOn(28,127,1);
      note5 = 1;
    }
  } else {
    if (note5 == 1) {
      MIDI.sendNoteOff(28,0,1);
    }
    note5 = 0;
  }

  if (buttonState6 == HIGH) {
    if (note6 == 0) {
      MIDI.sendNoteOn(29,127,1);
      note6 = 1;
    }
  } else {
    if (note6 == 1) {
      MIDI.sendNoteOff(29,0,1);
    }
    note6 = 0;
  }

  if (buttonState7 == HIGH) {
    if (note7 == 0) {
      MIDI.sendNoteOn(30,127,1);
      note7 = 1;
    }
  } else {
    if (note7 == 1) {
      MIDI.sendNoteOff(30,0,1);
    }
    note7 = 0;
  }

  if (buttonState8 == HIGH) {
    if (note8 == 0) {
      MIDI.sendNoteOn(31,127,1);
      note8 = 1;
    }
  } else {
    if (note8 == 1) {
      MIDI.sendNoteOff(31,0,1);
    }
    note8 = 0;
  }
 
  delay(1);
}

The main idea is: "As long as button X is pressed send note Y"
The MIDI message is sent but just on the release of the button and not when I press it, I'm using "standard pushbuttons" (like THIS) and I don't really know what am I doing wrong.

As you can see I'm quite new to the Arduino world and this is my very first project that I'm trying to make as a real one and not just a breadboard example.

If more information are needed just hit me up, I'll reply for sure!

Thank you in advance for any reply!

How are your switches wired? Details, please.

  pinMode(pushButton1, INPUT_PULLUP);
  int buttonState1 = digitalRead(pushButton1);
  // when button pressed:
  if (buttonState1 == HIGH) {

The inputs will be HIGH when the button is not pressed

When you have got this working then consider tidying up the code by using arrays and for loops to avoid the repeated code.

aarg:
How are your switches wired? Details, please.

Here's what the circuit looks like, it's just repeated 8 times with all the ground pins connected together.

UKHeliBob:

  pinMode(pushButton1, INPUT_PULLUP);
  int buttonState1 = digitalRead(pushButton1);
  // when button pressed:

if (buttonState1 == HIGH) {



The inputs will be HIGH when the button is [u]not[/u] pressed

I see, I'll try to correct this silly mistake, thank you very much!

UKHeliBob:
When you have got this working then consider tidying up the code by using arrays and for loops to avoid the repeated code.

You mean using for loops to declare the variables as arrays?

You mean using for loops to declare the variables as arrays?

Rather the other way round.

int pushButton1 = 0;
int pushButton2 = 1;
int pushButton3 = 2;
int pushButton4 = 3;
int pushButton5 = 5;
int pushButton6 = 6;
int pushButton7 = 8;
int pushButton8 = 9;

Variable names like this are usually crying out for arrays to be used

const byte buttonPins[] = {0, 1, 2, 3, 4, 5, 6, 8, 9}

and then for a for loop to read the state of the pins

for (int pin = 0; pin < sizeof(buttonPins); pin++)
{
  inputState = digitalRead(buttonPins[pin]);
  //code here depending on the state of the input
}

An observation. You are using pins 0 and 1 as inputs which prevents you using Serial.print() for debugging as they are the Tx and Rx pins for hardware serial.