Momentary button to function as a push button (MIDI Controller)

Hi All, Am trying to make my first midi controller.
I have used 3 buttons.


and I wanted the Momentary button to function as a push button, so you don’t have to hold the button until you finish the recording.

Am new to coding and finally got almost what I wanted.
Board used: Arduino UNO
Using Hairless Midi & Loop MIDI.

Any help would be much Appreciated.

#include <MIDI.h>

#include "Buttons.h"

#define NOTE_ONE 36
#define NOTE_TWO 37
#define NOTE_THREE 38

#define NOTE_ON_CMD 0x90
#define NOTE_OFF_CMD 0x80



Button Button1(4, NOTE_ONE);
Button Button2(3, NOTE_TWO);
Button Button3(2, NOTE_THREE);

Button *Buttons[] {&Button1,&Button2,&Button3};

void setup() {

void loop() {
  if (NUMBER_BUTTONS != 0) updateButtons();

void updateButtons() {

  for (int i = 0; i < NUMBER_BUTTONS; i++) {
      int state = Buttons[i]->getButtonState();
      //  Button is pressed     
      if (state == 0) 
         SendMidiToSerial(177, 47+i,127);
      //  Button is not pressed
      if (state == 1) 
        SendMidiToSerial(177, 47+i, 0);

void SendMidiToSerial (unsigned char word0, unsigned char word1, unsigned char word2) {

Thanks in Advance.

Board used: Arduino UNO

You could try something like this, using the Control Surface library I maintain:

#include <Control_Surface.h>

// Instantiate the MIDI interface to use (default baud rate 115200)
HairlessMIDI_Interface midi;

// Create an array of three button objects. 
// The input is latched: press once to enable, press again to disable.
NoteButtonLatched buttons[] {
  {4, 36}, // pin, note number
  {3, 37},
  {2, 38},

void setup() {
  Control_Surface.begin(); // Initialize Control Surface
void loop() {
  Control_Surface.loop(); // Update the Control Surface


Thanks Pieter. Am gonna try this . Much appreciated:)