Help with Midi controller - two pins not working

I've created several midi devices with great success. Now I have a project using an Arduino Due (for the # of pins and usb midi output). For some reason, pins 22 and 23 (Transpose pins) aren't responding. Everything else works perfectly. Any suggestions (yes, the code is a little sloppy and I plan on creating some functions to simplify the midi messaging ;-). Thanks in advance!

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <MIDIUSB.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const int MIDI_CHAN = 1;
const int DEBOUNCE_TIME = 40;
const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23}; // 13 notes & 4 chords & 2 Bank & 2 Transpose
byte note[] = {
  B00100,
  B00110,
  B00101,
  B00101,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note1[] = {
  B00111,
  B00100,
  B00100,
  B00100,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note2[] = {
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00111,
  B00111,
  B00111
};
const int midi_note_nums[4][13] = {
    {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // Bank 1 buttons 2-14 Cromatic Scale C - C octave
    {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, // Bank 2 buttons 2-14 Cromatic Scale C - C octave
    {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, // Bank 3 buttons 2-14 Cromatic Scale C - C octave
    {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, // Bank 4 buttons 2-14 Cromatic Scale C - C octave
};
const int midi_chord_nums[4][12] = {
    {29, 33, 36, 31, 34, 38, 34, 41, 38, 36, 40, 31 }, // Bank 1 buttons 15-18 - chords F, Gm, Bb, C
    {43, 47, 38, 36, 40, 43, 38, 42, 45, 40, 43, 47 }, // Bank 2 buttons 15-18 - chords G, C, D, Em
    {43, 48, 52, 43, 47, 50, 45, 40, 48, 41, 45, 48 }, // Bank 3 buttons 15-18 - chords C, G, Am, F
    {35, 38, 42, 43, 47, 50, 52, 49, 57, 38, 42, 45 }, // Bank 4 buttons 15-18 - chords Bm, G, A, D
};
const char *chord_chords[4][4] = {
    {"F ", "Gm", "Bb ", "C "}, // Display Chords Bank 1
    {"G ", "C ", "D ", "Em "}, // Display Chords Bank 2
    {"C ", "G ", "Am", "F "}, // Display Chords Bank 3
    {"Bm ", "G ", "A ", "D "}, // Display Chords Bank 4
};
Bounce buttons[23];
int currentBank = 0;
int noteOn;
int noteOn1;
int noteOn2;
int noteOn3;
int transpose = 0;
int transposebank = 0;

void update_display() {
lcd.setCursor(0,1);
lcd.print("                   "); 
lcd.setCursor(0,2);
lcd.print("                   ");
lcd.setCursor(0,3);
lcd.print("                   "); 
lcd.setCursor(0, 2);                 
lcd.print(" C# D#  F# G# A#");      
lcd.setCursor(0,3);                 
lcd.print("C  D  EF  G  A  BC");  
lcd.setCursor(0, 0);
lcd.print("Bank:" + String(1+currentBank));
lcd.setCursor(8, 0); 
lcd.print("Chord:   ");
lcd.setCursor(17, 0);
lcd.print("T:");
lcd.print(String(transposebank));
}
void setup() {
    for (int i = 0; i < 22; i++) // check pins as 18+ cause a problem
    {
        pinMode(i, INPUT_PULLUP);
        buttons[i].attach(i);
        buttons[i].interval(DEBOUNCE_TIME);
    }  
//
// Initialize the display
// Clear the display
// Turn on the backlight
// Populate the display with Bank, Chord, and Notes representing button layout on beyboard 
//
    lcd.init();
    lcd.backlight();
    lcd.createChar(0, note);  
    lcd.createChar(1, note1);  
    lcd.createChar(2, note2);  
    lcd.setCursor(0, 2);
    lcd.print(" C# D#  F# G# A#");
    lcd.setCursor(0, 3);
    lcd.print("C  D  EF  G  A  BC");
    lcd.setCursor(0, 0);
    lcd.print("Bank:" + String(1+currentBank));
    lcd.setCursor(8,0);
    lcd.print("Chord:");
    lcd.setCursor(17, 0);
    lcd.print("T:");
    lcd.print(String(transposebank));
    Serial.begin(31250);
}
void loop()
{ 
  for (int i = 0; i < 22; i++) { // update buttons
    buttons[i].update();       
      if (buttons[i].fell()) {
         if (i==0)  {           // Check for Bank Down Button Press 
               if (currentBank==0)
                { 
                  currentBank=3;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank = currentBank-1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==1) {     // Check for Bank Up Button Press
               if (currentBank==3)
                { 
                  currentBank=0;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank= currentBank+1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==22) {     // Check for Transpose Down Button Press 
               if (transposebank==0)
                { 
                  transpose=transpose+36;
                  transposebank=3;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(String(transposebank));
                } else {
                   transpose = transpose-12;
                   transposebank = transposebank-1;  
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(String(transposebank));
                }   
        } else if (i==23) {   // Check for Transpose Up Button Press // Check for Transpose Up Button Press  
              if (transposebank==3)
                { 
                 transposebank=0;
                  transpose = transpose-36;
                  lcd.setCursor(16, 0);
                  lcd.print("T:");
                  lcd.print(String(transposebank));
                } else {
                   transposebank= transposebank+1;
                   transpose = transpose+12; 
                   lcd.setCursor(16, 0);
                   lcd.print("T:");
                   lcd.print(String(transposebank));
                }      
        } else if (i==2) {      
                   update_display();
                   lcd.setCursor(0, 1);  
                   lcd.write(byte(0));
                   midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                   MidiUSB.sendMIDI(noteOn);
        } else if (i==4) {                       
                  update_display();
                  lcd.setCursor(3, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==6) {              
                  update_display();
                  lcd.setCursor(6, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==7){              
                  update_display();
                  lcd.setCursor(7, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==9) {              
                  update_display();
                  lcd.setCursor(10, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                       
        } else if (i==11) {              
                  update_display();
                  lcd.setCursor(13, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==13) {              
                  update_display();
                  lcd.setCursor(16, 1); 
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                      
        } else if (i==14) {              
                  update_display();
                  lcd.setCursor(17, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==3) {              
                  lcd.setCursor(1, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==5) {              
                  update_display();
                  lcd.setCursor(4, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==8) {              
                  update_display();
                  lcd.setCursor(8, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==10){              
                  update_display();
                  lcd.setCursor(11, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==12) {               
                  update_display();
                  lcd.setCursor(14, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                  
        } else if (i == 15) {                                                                           // check for chord press button - button 15 to 18
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                        // Displays the chord played based on the chord_chords array
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-15]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-14]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 16) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                 // Displays the chord played based on the chord_chords array 
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-12]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 17) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  // Displays the chord played based on the chord_chords array 
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-10]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 18) { 
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-8]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-7]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } 
     } else if (buttons[i].rose()) { // Check if button rose
           update_display(); // update the display
           midiEventPacket_t noteOff = {0x08, 0x80 | 0, noteOn, 0};       // if note button rose, turn off note
           MidiUSB.sendMIDI(noteOff);
           midiEventPacket_t noteOff1 = {0x08, 0x80 | 0, noteOn1, 0};    // if chord button rose, turn off note 1 of chord
           MidiUSB.sendMIDI(noteOff1);
           midiEventPacket_t noteOff2 = {0x08, 0x80 | 0, noteOn2, 0};    // if chord button rose, turn off note 2 of chord
           MidiUSB.sendMIDI(noteOff2);
           midiEventPacket_t noteOff3 = {0x08, 0x80 | 0, noteOn3, 0};    // if chord button rose, turn off note 3 of chord
           MidiUSB.sendMIDI(noteOff3);
          } 
  }               
}        

Hello peetem

I assume that you have written the programme by yourself, then it is quite easy to find the error.

There's a trick to figuring out why something isn't working:

Use a logic analyzer to see what happens.
Put Serial.print statements at various places in the code as diagnostic prints to see the values of variables, especially ones that control the motors, and determine whether they meet your expectations.

Have a nice day and enjoy coding in C++.

p.s.

In general - arrays and structs are your friends.
Don't duplicate code in your sketch. Write code once - use it multiple times.
You should not use magic numbers. The I/O pins and cases love to have a functional name.

This is not right

    for (int i = 0; i < 22; i++) // check pins as 18+ cause a problem
    {
        pinMode(i, INPUT_PULLUP);
        buttons[i].attach(i);
        buttons[i].interval(DEBOUNCE_TIME);
    }  

because you're not using the pins defined in the array.
It should be

    for (int i = 0; i < 21; i++) // check pins as 18+ cause a problem
    {
        pinMode(ButtonPins[i], INPUT_PULLUP);
        buttons[i].attach(ButtonPins[i]);
        buttons[i].interval(DEBOUNCE_TIME);
    }  

or directly

    for (int i = 0; i < 21; i++) // check pins as 18+ cause a problem
    {
        buttons[i].attach(ButtonPins[i], INPUT_PULLUP);
        buttons[i].interval(DEBOUNCE_TIME);
    }  

Regards

The index in an an array starts at zero. So the line of code above will only handle buttons up to 22.

Your for loops:-

only supports buttons up to 21. So that is where you are loosing the other one.

How are these push buttons being wired? The use of the Bounce2 library hide from us what you actually have.

Hello

C++ provides a nice instruction to work with arrays.

https://www.learncpp.com/cpp-tutorial/range-based-for-loops-for-each/

Many thanks for the help. Now only button 21 (pin 23) isn't working (Transpose Up). Any suggestions?

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <MIDIUSB.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const int MIDI_CHAN = 1;
const int DEBOUNCE_TIME = 40;
const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23}; // 13 notes & 4 chords & 2 Bank & 2 Transpose
byte note[] = {
  B00100,
  B00110,
  B00101,
  B00101,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note1[] = {
  B00111,
  B00100,
  B00100,
  B00100,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note2[] = {
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00111,
  B00111,
  B00111
};
const int midi_note_nums[4][13] = {
    {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // Bank 1 buttons 2-14 Cromatic Scale C - C octave
    {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, // Bank 2 buttons 2-14 Cromatic Scale C - C octave
    {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, // Bank 3 buttons 2-14 Cromatic Scale C - C octave
    {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, // Bank 4 buttons 2-14 Cromatic Scale C - C octave
};
const int midi_chord_nums[4][12] = {
    {29, 33, 36, 31, 34, 38, 34, 41, 38, 36, 40, 31 }, // Bank 1 buttons 15-18 - chords F, Gm, Bb, C
    {43, 47, 38, 36, 40, 43, 38, 42, 45, 40, 43, 47 }, // Bank 2 buttons 15-18 - chords G, C, D, Em
    {43, 48, 52, 43, 47, 50, 45, 40, 48, 41, 45, 48 }, // Bank 3 buttons 15-18 - chords C, G, Am, F
    {35, 38, 42, 43, 47, 50, 52, 49, 57, 38, 42, 45 }, // Bank 4 buttons 15-18 - chords Bm, G, A, D
};
const char *chord_chords[4][4] = {
    {"F ", "Gm", "Bb ", "C "}, // Display Chords Bank 1
    {"G ", "C ", "D ", "Em "}, // Display Chords Bank 2
    {"C ", "G ", "Am", "F "}, // Display Chords Bank 3
    {"Bm ", "G ", "A ", "D "}, // Display Chords Bank 4
};
Bounce buttons[23];
int currentBank = 0;
int noteOn;
int noteOn1;
int noteOn2;
int noteOn3;
int transpose = 0;
int transposebank = 0;

void update_display() {
lcd.setCursor(0,1);
lcd.print("                   "); 
lcd.setCursor(0,2);
lcd.print("                   ");
lcd.setCursor(0,3);
lcd.print("                   "); 
lcd.setCursor(0, 2);                 
lcd.print(" C# D#  F# G# A#");      
lcd.setCursor(0,3);                 
lcd.print("C  D  EF  G  A  BC");  
lcd.setCursor(0, 0);
lcd.print("Bank:" + String(1+currentBank));
lcd.setCursor(8, 0); 
lcd.print("Chord:   ");
lcd.setCursor(17, 0);
lcd.print("T:");
lcd.print(String(transposebank));
}
void setup() {
    for (int i = 0; i < 22; i++) 
    {
        pinMode(ButtonPins[i], INPUT_PULLUP);
        buttons[i].attach(ButtonPins[i]);
        buttons[i].interval(DEBOUNCE_TIME);
    }  
//
// Initialize the display
// Clear the display=
// Turn on the backlight
// Populate the display with Bank, Chord, Transpose and Notes representing button layout on beyboard 
//
    lcd.init();
    lcd.backlight();
    lcd.createChar(0, note);  
    lcd.createChar(1, note1);  
    lcd.createChar(2, note2);  
    lcd.setCursor(0, 2);
    lcd.print(" C# D#  F# G# A#");
    lcd.setCursor(0, 3);
    lcd.print("C  D  EF  G  A  BC");
    lcd.setCursor(0, 0);
    lcd.print("Bank:" + String(1+currentBank));
    lcd.setCursor(8,0);
    lcd.print("Chord:");
    lcd.setCursor(17, 0);
    lcd.print("T:");
    lcd.print(String(transposebank));
    Serial.begin(31250);
}
void loop()
{ 
  for (int i = 0; i < 22; i++) { // update buttons
    buttons[i].update();       
      if (buttons[i].fell()) {
         if (i==0)  {           // Check for Bank Down Button Press 
               if (currentBank==0)
                { 
                  currentBank=3;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank = currentBank-1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==1) {     // Check for Bank Up Button Press
               if (currentBank==3)
                { 
                  currentBank=0;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank= currentBank+1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==20) {     // Check for Transpose Down Button Press 
               if (transposebank==0)
                { 
                  transpose=transpose+36;
                  transposebank=3;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transpose = transpose-12;
                   transposebank = transposebank-1;  
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }   
        } else if (i==21) {   // Check for Transpose Up Button Press // Check for Transpose Up Button Press  
              if (transposebank==3)
                { 
                  transpose = transpose-36;
                  transposebank=0;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transposebank= transposebank+1;
                   transpose = transpose+12; 
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }      
        } else if (i==2) {      
                   update_display();
                   lcd.setCursor(0, 1);  
                   lcd.write(byte(0));
                   midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                   MidiUSB.sendMIDI(noteOn);
        } else if (i==4) {                       
                  update_display();
                  lcd.setCursor(3, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==6) {              
                  update_display();
                  lcd.setCursor(6, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==7){              
                  update_display();
                  lcd.setCursor(7, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==9) {              
                  update_display();
                  lcd.setCursor(10, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                       
        } else if (i==11) {              
                  update_display();
                  lcd.setCursor(13, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==13) {              
                  update_display();
                  lcd.setCursor(16, 1); 
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                      
        } else if (i==14) {              
                  update_display();
                  lcd.setCursor(17, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==3) {              
                  lcd.setCursor(1, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==5) {              
                  update_display();
                  lcd.setCursor(4, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==8) {              
                  update_display();
                  lcd.setCursor(8, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==10){              
                  update_display();
                  lcd.setCursor(11, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==12) {               
                  update_display();
                  lcd.setCursor(14, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                  
        } else if (i == 15) {                                                                           // check for chord press button - button 15 to 18
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                        // Displays the chord played based on the chord_chords array
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-15]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-14]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 16) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                 
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-12]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 17) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-10]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 18) { 
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-8]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-7]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } 
     } else if (buttons[i].rose()) { // Check if button rose
           update_display(); // update the display
           midiEventPacket_t noteOff = {0x08, 0x80 | 0, noteOn, 0};      // if note button rose, turn off note
           MidiUSB.sendMIDI(noteOff);
           midiEventPacket_t noteOff1 = {0x08, 0x80 | 0, noteOn1, 0};    // if chord button rose, turn off note 1 of chord
           MidiUSB.sendMIDI(noteOff1);
           midiEventPacket_t noteOff2 = {0x08, 0x80 | 0, noteOn2, 0};    // if chord button rose, turn off note 2 of chord
           MidiUSB.sendMIDI(noteOff2);
           midiEventPacket_t noteOff3 = {0x08, 0x80 | 0, noteOn3, 0};    // if chord button rose, turn off note 3 of chord
           MidiUSB.sendMIDI(noteOff3);
          } 
  }               
}        

Yes, please read what I wrote in my post #4 about your for loop at the start of the loop function and the setup function.

In fact reed the whole of my post as you seem to be ignoring it all.

I did read your post, so apologies if it seemed I skipped over it. :wink: However, if I made the For loop larger, everything locks up. And If I make the Bounce buttons [23] smaller, everything locks up.

I only have 21 buttons anyway. But I'll adjust again per your recommendations and maybe can get it to work.

Adjusted the Bounce buttons [24] and For i loops to i<24. Button on pin 22 still doesn't work.

Maybe I misunderstood your post?

IDK what your problem is, but I got lost counting. You can get the compiler to count for you:

const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23};

const int nButtons = sizeof ButtonPins / sizeof ButtonPins[0];

then run your loops like

  for (int ii = 0; ii < nButtons; ii++) {
// loop over all buttona
  }

You could print nButtons to see how many you actually put in the array. Computers count good.

HTH

a7

If you have 21 buttons it's 21, not 23 and even less 24!

Bounce buttons[21];
for (int i = 0; i < 21; i++) // check pins as 18+ cause a problem
    {

or like @alto777 says (I like it)

const int nButtons = sizeof ButtonPins / sizeof ButtonPins[0];

Bounce buttons[nButtons];
for (int i = 0; i < nButtons ; i++) // check pins as 18+ cause a problem
    {

Good eye. All arrays that need to hold nButtons number of things will need an explicit dimension, but you can use nButtons there too, not a number like 42.

a7

I tried 21 for the buttons and the loop. Locked up.

Made code changes as suggested. Nothing. I even assigned another pin for the button on pin 22 (tried pins 24 and 54), nothing. I added code to debug - no button press is detected on the serial print. Button tests fine. Wire tests fine.

I do see the display blink on the bottom half like the update display function was called (it isn't in the case) when i press the button. But nothing else happens. The non-working portion of the code is the else if loop testing if i==21 (button pin 22).

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <MIDIUSB.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const int MIDI_CHAN = 1;
const int DEBOUNCE_TIME = 40;
const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23}; // 13 notes & 4 chords & 2 Bank & 2 Transpose
byte note[] = {
  B00100,
  B00110,
  B00101,
  B00101,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note1[] = {
  B00111,
  B00100,
  B00100,
  B00100,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note2[] = {
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00111,
  B00111,
  B00111
};
const int midi_note_nums[4][13] = {
    {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // Bank 1 buttons 2-14 Cromatic Scale C - C octave
    {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, // Bank 2 buttons 2-14 Cromatic Scale C - C octave
    {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, // Bank 3 buttons 2-14 Cromatic Scale C - C octave
    {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, // Bank 4 buttons 2-14 Cromatic Scale C - C octave
};
const int midi_chord_nums[4][12] = {
    {29, 33, 36, 31, 34, 38, 34, 41, 38, 36, 40, 31 }, // Bank 1 buttons 15-18 - chords F, Gm, Bb, C
    {43, 47, 38, 36, 40, 43, 38, 42, 45, 40, 43, 47 }, // Bank 2 buttons 15-18 - chords G, C, D, Em
    {43, 48, 52, 43, 47, 50, 45, 40, 48, 41, 45, 48 }, // Bank 3 buttons 15-18 - chords C, G, Am, F
    {35, 38, 42, 43, 47, 50, 52, 49, 57, 38, 42, 45 }, // Bank 4 buttons 15-18 - chords Bm, G, A, D
};
const char *chord_chords[4][4] = {
    {"F ", "Gm", "Bb ", "C "}, // Display Chords Bank 1
    {"G ", "C ", "D ", "Em "}, // Display Chords Bank 2
    {"C ", "G ", "Am", "F "}, // Display Chords Bank 3
    {"Bm ", "G ", "A ", "D "}, // Display Chords Bank 4
};
Bounce buttons[21];
int currentBank = 0;
int noteOn;
int noteOn1;
int noteOn2;
int noteOn3;
int transpose = 0;
int transposebank = 0;

void update_display() {
lcd.setCursor(0,1);
lcd.print("                   "); 
lcd.setCursor(0,2);
lcd.print("                   ");
lcd.setCursor(0,3);
lcd.print("                   "); 
lcd.setCursor(0, 2);                 
lcd.print(" C# D#  F# G# A#");      
lcd.setCursor(0,3);                 
lcd.print("C  D  EF  G  A  BC");  
lcd.setCursor(0, 0);
lcd.print("Bank:" + String(1+currentBank));
lcd.setCursor(8, 0); 
lcd.print("Chord:   ");
lcd.setCursor(17, 0);
lcd.print("T:");
lcd.print(String(transposebank));
}
const int nButtons = sizeof ButtonPins / sizeof ButtonPins[0];
void setup() {
    for (int i = 0; i < nButtons; i++)
    //for (int i = 0; i < 24; i++) 
    {
        pinMode(ButtonPins[i], INPUT_PULLUP);
        buttons[i].attach(ButtonPins[i]);
        buttons[i].interval(DEBOUNCE_TIME);
    }  
//
// Initialize the display
// Clear the display=
// Turn on the backlight
// Populate the display with Bank, Chord, Transpose and Notes representing button layout on beyboard 
//
    lcd.init();
    lcd.backlight();
    lcd.createChar(0, note);  
    lcd.createChar(1, note1);  
    lcd.createChar(2, note2);  
    lcd.setCursor(0, 2);
    lcd.print(" C# D#  F# G# A#");
    lcd.setCursor(0, 3);
    lcd.print("C  D  EF  G  A  BC");
    lcd.setCursor(0, 0);
    lcd.print("Bank:" + String(1+currentBank));
    lcd.setCursor(8,0);
    lcd.print("Chord:");
    lcd.setCursor(17, 0);
    lcd.print("T:");
    lcd.print(String(transposebank));
    Serial.begin(31250);
}
void loop()
{ 
  for (int i = 0; i < nButtons; i++){ 
  //for (int i = 0; i < 23; i++) { // update buttons
    buttons[i].update();       
      if (buttons[i].fell()) {
         if (i==0)  {           // Check for Bank Down Button Press 
               if (currentBank==0)
                { 
                  currentBank=3;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank = currentBank-1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==1) {     // Check for Bank Up Button Press
               if (currentBank==3)
                { 
                  currentBank=0;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank= currentBank+1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==20) {     // Check for Transpose Down Button Press 
               if (transposebank==0)
                { 
                  transpose = transpose+36;
                  transposebank = 3;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transpose = transpose-12;
                   transposebank = transposebank-1;  
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }   
        } else if (i==21) {   // Check for Transpose Up Button Press 
              if (transposebank==3)
                { 
                  transpose = transpose-36;
                  transposebank = 0;
                  lcd.setCursor(17, 0);
                  lcd.print("B:");
                  lcd.print(transposebank);
                } else {
                   transposebank= transposebank+1;
                   transpose = transpose+12; 
                   lcd.setCursor(17, 0);
                   lcd.print("B:");
                   lcd.print(transposebank);
                }      
        } else if (i==2) {      
                   update_display();
                   lcd.setCursor(0, 1);  
                   lcd.write(byte(0));
                   midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                   MidiUSB.sendMIDI(noteOn);
        } else if (i==4) {                       
                  update_display();
                  lcd.setCursor(3, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==6) {              
                  update_display();
                  lcd.setCursor(6, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==7){              
                  update_display();
                  lcd.setCursor(7, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==9) {              
                  update_display();
                  lcd.setCursor(10, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                       
        } else if (i==11) {              
                  update_display();
                  lcd.setCursor(13, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==13) {              
                  update_display();
                  lcd.setCursor(16, 1); 
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                      
        } else if (i==14) {              
                  update_display();
                  lcd.setCursor(17, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==3) {              
                  lcd.setCursor(1, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==5) {              
                  update_display();
                  lcd.setCursor(4, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==8) {              
                  update_display();
                  lcd.setCursor(8, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==10){              
                  update_display();
                  lcd.setCursor(11, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==12) {               
                  update_display();
                  lcd.setCursor(14, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                  
        } else if (i == 15) {                                                                           // check for chord press button - button 15 to 18
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                        // Displays the chord played based on the chord_chords array
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-15]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-14]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 16) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                 
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-12]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 17) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-10]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 18) { 
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-8]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-7]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } 
     } else if (buttons[i].rose()) { // Check if button rose
           update_display(); // update the display
           midiEventPacket_t noteOff = {0x08, 0x80 | 0, noteOn, 0};      // if note button rose, turn off note
           MidiUSB.sendMIDI(noteOff);
           midiEventPacket_t noteOff1 = {0x08, 0x80 | 0, noteOn1, 0};    // if chord button rose, turn off note 1 of chord
           MidiUSB.sendMIDI(noteOff1);
           midiEventPacket_t noteOff2 = {0x08, 0x80 | 0, noteOn2, 0};    // if chord button rose, turn off note 2 of chord
           MidiUSB.sendMIDI(noteOff2);
           midiEventPacket_t noteOff3 = {0x08, 0x80 | 0, noteOn3, 0};    // if chord button rose, turn off note 3 of chord
           MidiUSB.sendMIDI(noteOff3);
          } 
  }               
}        
        } else if (i==21) {   // Check for Transpose Up Button Press // Check for Transpose Up Button Press  
 

If the index of buttons[] starts at 0 and ends at 20 (total 21 buttons) there can never be one with index 21 that is valid.

And if you tempt yourself and put back 22 or 23 even 24, the button[21] is not assigned to any pin because ButtonPins[] contains 21 values (indexed 0 to 20, obviously)

Fixed that for ya.

no button press is detected on the serial print

What serial print?

Make the changes we've suggested that you haven't, add the serial printing that doesn't, and post the entire sketch.

a7

I tried to capture all the suggestions. In my earlier code I removed the serial print lines, they have been added back.

Please forgive my ignorance here. This stuff comes easy to some, but not me. :wink:

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <MIDIUSB.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

const int MIDI_CHAN = 1;
const int DEBOUNCE_TIME = 40;
const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23}; // 13 notes & 4 chords & 2 Bank & 2 Transpose
byte note[] = {
  B00100,
  B00110,
  B00101,
  B00101,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note1[] = {
  B00111,
  B00100,
  B00100,
  B00100,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note2[] = {
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00111,
  B00111,
  B00111
};
const int midi_note_nums[4][13] = {
    {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // Bank 1 buttons 2-14 Cromatic Scale C - C octave
    {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36}, // Bank 2 buttons 2-14 Cromatic Scale C - C octave
    {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}, // Bank 3 buttons 2-14 Cromatic Scale C - C octave
    {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, // Bank 4 buttons 2-14 Cromatic Scale C - C octave
};
const int midi_chord_nums[4][12] = {
    {29, 33, 36, 31, 34, 38, 34, 41, 38, 36, 40, 31 }, // Bank 1 buttons 15-18 - chords F, Gm, Bb, C
    {43, 47, 38, 36, 40, 43, 38, 42, 45, 40, 43, 47 }, // Bank 2 buttons 15-18 - chords G, C, D, Em
    {43, 48, 52, 43, 47, 50, 45, 40, 48, 41, 45, 48 }, // Bank 3 buttons 15-18 - chords C, G, Am, F
    {35, 38, 42, 43, 47, 50, 52, 49, 57, 38, 42, 45 }, // Bank 4 buttons 15-18 - chords Bm, G, A, D
};
const char *chord_chords[4][4] = {
    {"F ", "Gm", "Bb ", "C "}, // Display Chords Bank 1
    {"G ", "C ", "D ", "Em "}, // Display Chords Bank 2
    {"C ", "G ", "Am", "F "}, // Display Chords Bank 3
    {"Bm ", "G ", "A ", "D "}, // Display Chords Bank 4
};

int currentBank = 0;
int noteOn;
int noteOn1;
int noteOn2;
int noteOn3;
int transpose = 0;
int transposebank = 0;

void update_display() {
lcd.setCursor(0,1);
lcd.print("                   "); 
lcd.setCursor(0,2);
lcd.print("                   ");
lcd.setCursor(0,3);
lcd.print("                   "); 
lcd.setCursor(0, 2);                 
lcd.print(" C# D#  F# G# A#");      
lcd.setCursor(0,3);                 
lcd.print("C  D  EF  G  A  BC");  
lcd.setCursor(0, 0);
lcd.print("Bank:" + String(1+currentBank));
lcd.setCursor(8, 0); 
lcd.print("Chord:   ");
lcd.setCursor(17, 0);
lcd.print("T:");
lcd.print(String(transposebank));
}
const int nButtons = sizeof ButtonPins / sizeof ButtonPins[0];
Bounce buttons[nButtons];

void setup() {
    for (int i = 0; i < nButtons; i++)
    //for (int i = 0; i < 24; i++) 
    {
        pinMode(ButtonPins[i], INPUT_PULLUP);
        buttons[i].attach(ButtonPins[i]);
        buttons[i].interval(DEBOUNCE_TIME);
    }  
//
// Initialize the display
// Clear the display=
// Turn on the backlight
// Populate the display with Bank, Chord, Transpose and Notes representing button layout on beyboard 
//
    lcd.init();
    lcd.backlight();
    lcd.createChar(0, note);  
    lcd.createChar(1, note1);  
    lcd.createChar(2, note2);  
    lcd.setCursor(0, 2);
    lcd.print(" C# D#  F# G# A#");
    lcd.setCursor(0, 3);
    lcd.print("C  D  EF  G  A  BC");
    lcd.setCursor(0, 0);
    lcd.print("Bank:" + String(1+currentBank));
    lcd.setCursor(8,0);
    lcd.print("Chord:");
    lcd.setCursor(17, 0);
    lcd.print("T:");
    lcd.print(String(transposebank));
    Serial.begin(31250);
}
void loop()
{ 
  for (int i = 0; i < nButtons; i++){ 
  //for (int i = 0; i < 23; i++) { // update buttons
    buttons[i].update();       
      if (buttons[i].fell()) {
         if (i==0)  {           // Check for Bank Down Button Press 
               if (currentBank==0)
                { 
                  currentBank=3;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank = currentBank-1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==1) {     // Check for Bank Up Button Press
               if (currentBank==3)
                { 
                  currentBank=0;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank= currentBank+1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==20) {     // Check for Transpose Down Button Press 
               if (transposebank==0)
                { 
                  transpose = transpose+36;
                  transposebank = 3;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transpose = transpose-12;
                   transposebank = transposebank-1;  
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }   
        } else if (i==21) {   // Check for Transpose Up Button Press 
              if (transposebank==3)
                { 
                  transpose = transpose-36;
                  transposebank = 0;
                  Serial.print("Button Push");
                  lcd.setCursor(17, 0);
                  lcd.print("B:");
                  lcd.print(transposebank);
                } else {
                   transposebank= transposebank+1;
                   transpose = transpose+12; 
                   Serial.print("Button Push");
                   lcd.setCursor(17, 0);
                   lcd.print("B:");
                   lcd.print(transposebank);
                }      
        } else if (i==2) {      
                   update_display();
                   lcd.setCursor(0, 1);  
                   lcd.write(byte(0));
                   midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                   MidiUSB.sendMIDI(noteOn);
        } else if (i==4) {                       
                  update_display();
                  lcd.setCursor(3, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==6) {              
                  update_display();
                  lcd.setCursor(6, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==7){              
                  update_display();
                  lcd.setCursor(7, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==9) {              
                  update_display();
                  lcd.setCursor(10, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                       
        } else if (i==11) {              
                  update_display();
                  lcd.setCursor(13, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==13) {              
                  update_display();
                  lcd.setCursor(16, 1); 
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                      
        } else if (i==14) {              
                  update_display();
                  lcd.setCursor(17, 1);  
                  lcd.write(byte(0));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==3) {              
                  lcd.setCursor(1, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==5) {              
                  update_display();
                  lcd.setCursor(4, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==8) {              
                  update_display();
                  lcd.setCursor(8, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==10){              
                  update_display();
                  lcd.setCursor(11, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  // Sends Midi note pressed from the midi_note_nums array
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==12) {               
                  update_display();
                  lcd.setCursor(14, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 127};  
                  MidiUSB.sendMIDI(noteOn);                                  
        } else if (i == 15) {                                                                           // check for chord press button - button 15 to 18
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                        // Displays the chord played based on the chord_chords array
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-15]+transpose, 127}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-14]+transpose, 127}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 16) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                 
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-12]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 17) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-10]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 18) { 
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));                  
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn1);
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-8]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn2);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-7]+transpose, 127}; 
                  MidiUSB.sendMIDI(noteOn3);
        } 
     } else if (buttons[i].rose()) { // Check if button rose
           update_display(); // update the display
           midiEventPacket_t noteOff = {0x08, 0x80 | 0, noteOn, 0};      // if note button rose, turn off note
           MidiUSB.sendMIDI(noteOff);
           midiEventPacket_t noteOff1 = {0x08, 0x80 | 0, noteOn1, 0};    // if chord button rose, turn off note 1 of chord
           MidiUSB.sendMIDI(noteOff1);
           midiEventPacket_t noteOff2 = {0x08, 0x80 | 0, noteOn2, 0};    // if chord button rose, turn off note 2 of chord
           MidiUSB.sendMIDI(noteOff2);
           midiEventPacket_t noteOff3 = {0x08, 0x80 | 0, noteOn3, 0};    // if chord button rose, turn off note 3 of chord
           MidiUSB.sendMIDI(noteOff3);
          } 
  }               
}        

Figured it out. Appreciate everyone's help.

Post the code that works now. For us and for others who find this thread searching for solutions to whatever their problems are.

a7

Code fixed for midi foot keyboard controller. Note buttons are arranged like a keyboard on the controller and displayed accordingly on the LCD. 8th notes appear above the note that was pushed. Controller also has 4 chord buttons (pre-programmed), 2 bank select Up/Down (up to 4 banks), and 2 octave buttons - Octave Up/Down for up to 3 octaves increased for all note/chords.

#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <MIDIUSB.h>

LiquidCrystal_I2C lcd(0x27, 20, 4); 

// const int MIDI_CHAN = 1; // Note used but can be if want to add a midi channel select button later
const int DEBOUNCE_TIME = 40; // Debounce time
const int ButtonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23}; // 13 notes & 4 chords & 2 Bank & 2 Transpose - 21 buttons
byte note[] = {  // Creates a special character - 8th note that will be diplayed when note button is pushed on natural note (e.g., C)
  B00100,
  B00110,
  B00101,
  B00101,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note1[] = {  // Creates half of special character bar 8th note that displays above #'d notes (e.g., C#)
  B00111,
  B00100,
  B00100,
  B00100,
  B00100,
  B11100,
  B11100,
  B11100
};
byte note2[] = {  // Creates other half of special character bar 8th note that displays above #'d notes (e.g., C#)
  B11111,
  B00001,
  B00001,
  B00001,
  B00001,
  B00111,
  B00111,
  B00111
};
const int midi_note_nums[4][13] = {
    {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, // Bank 1 buttons 2-14 Cromatic Scale C - C octave
    {60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}, // Bank 2 buttons 2-14 Cromatic Scale C - C octave
    {72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84}, // Bank 3 buttons 2-14 Cromatic Scale C - C octave
    {84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96}, // Bank 4 buttons 2-14 Cromatic Scale C - C octave
};
const int midi_chord_nums[4][12] = {
    {53, 57, 60, 55, 58, 62, 58, 65, 62, 60, 64, 55  }, // Bank 1 buttons 15-18 - chords F, Gm, Bb, C (3 notes/chord)
    {55, 59, 50, 60, 52, 55, 50, 54, 57, 52, 55, 59 }, // Bank 2 buttons 15-18 - chords G, C, D, Em
    {55, 60, 64, 55, 59, 62, 57, 64, 60, 53, 57, 60 }, // Bank 3 buttons 15-18 - chords C, G, Am, F
    {59, 62, 54, 55, 59, 62, 64, 61, 69, 62, 66, 57 }, // Bank 4 buttons 15-18 - chords Bm, G, A, D
};
const char *chord_chords[4][4] = {
    {"F ", "Gm", "Bb ", "C "}, // Display Chords Bank 1
    {"G ", "C ", "D ", "Em "}, // Display Chords Bank 2
    {"C ", "G ", "Am", "F "}, // Display Chords Bank 3
    {"Bm ", "G ", "A ", "D "}, // Display Chords Bank 4
};

int currentBank = 0;
int noteOn;
int noteOn1;
int noteOn2;
int noteOn3;
int notetrack;
int note1track;
int note2track;
int note3track;
int transpose = 0; 
int transposebank = 0;

void update_display() {
lcd.setCursor(0,1);
lcd.print("                   "); 
lcd.setCursor(0,2);
lcd.print("                   ");
lcd.setCursor(0,3);
lcd.print("                   "); 
lcd.setCursor(0, 2);                 
lcd.print(" C# D#  F# G# A#");      
lcd.setCursor(0,3);                 
lcd.print("C  D  EF  G  A  BC");  
lcd.setCursor(0, 0);
lcd.print("Bank:" + String(1+currentBank));
lcd.setCursor(8, 0); 
lcd.print("Chord:   ");
lcd.setCursor(17, 0);
lcd.print("T:");
lcd.print(String(transposebank));
}

const int nButtons = sizeof ButtonPins / sizeof ButtonPins[0];
Bounce buttons[nButtons];

void setup() {
    for (int i = 0; i < nButtons; i++)
    //for (int i = 0; i < 24; i++) 
    {
        pinMode(ButtonPins[i], INPUT_PULLUP);
        buttons[i].attach(ButtonPins[i]);
        buttons[i].interval(DEBOUNCE_TIME);
    }  
//
// Initialize the display
// Clear the display
// Turn on the backlight
// Populate the display with Bank, Chord, Transpose, and Notes representing button layout on beyboard 
//
    lcd.init();
    lcd.backlight();
    lcd.createChar(0, note);  
    lcd.createChar(1, note1);  
    lcd.createChar(2, note2);  
    lcd.setCursor(0, 2);
    lcd.print(" C# D#  F# G# A#");
    lcd.setCursor(0, 3);
    lcd.print("C  D  EF  G  A  BC");
    lcd.setCursor(0, 0);
    lcd.print("Bank:" + String(1+currentBank));
    lcd.setCursor(8,0);
    lcd.print("Chord:");
    lcd.setCursor(17, 0);
    lcd.print("T:");
    lcd.print(String(transposebank));
    Serial.begin(31250);
}
void loop()
{ 
  for (int i = 0; i < nButtons; i++){ 
    buttons[i].update();       
      if (buttons[i].fell()) {
         if (i==0)  {                          // Check for Bank Down Button Press 
               if (currentBank==0)
                { 
                  currentBank=3;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank = currentBank-1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==1) {                    // Check for Bank Up Button Press
               if (currentBank==3)
                { 
                  currentBank=0;
                  lcd.setCursor(0, 0);
                  lcd.print("Bank:");
                  lcd.print(currentBank+1);
                } else {
                   currentBank= currentBank+1;  
                   lcd.setCursor(0, 0);
                   lcd.print("Bank:");
                   lcd.print(currentBank+1);
                }   
        } else if (i==20) {                // Check for Transpose Down Button Press 
               if (transposebank==0)
                { 
                  transpose = transpose+36;  // If 0 octaves up and Down button pushed, rolls back to 3 octaves up (+36 to midi note)
                  transposebank = 3;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transpose = transpose-12; // If Octave +3, +2, or +1 Octave active, deducts one octave (-12 to midi note) for button push
                   transposebank = transposebank-1;  
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }   
        } else if (i==19) {                 // Check for Transpose Up Button Press
              if (transposebank==3)
                { 
                  transpose = transpose-36; // If 3 octaves up (+3), deducts -36 to midi note and rolls back over to ) octaves up
                  transposebank = 0;
                  lcd.setCursor(17, 0);
                  lcd.print("T:");
                  lcd.print(transposebank);
                } else {
                   transposebank= transposebank+1;
                   transpose = transpose+12;   // If UP pushed adds +12 ot midi note for button push 
                   lcd.setCursor(17, 0);
                   lcd.print("T:");
                   lcd.print(transposebank);
                }      
        } else if (i==2) {                                                                                      // Checks for Note button push
                   update_display();
                   lcd.setCursor(0, 1);  
                   lcd.write(byte(0));
                   notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                   midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  // Sends Midi note pressed from the midi_note_nums array
                   MidiUSB.sendMIDI(noteOn);
        } else if (i==4) {                       
                  update_display();
                  lcd.setCursor(3, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  // Sends Midi note pressed from the midi_note_nums array
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==6) {              
                  update_display();
                  lcd.setCursor(6, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==7){              
                  update_display();
                  lcd.setCursor(7, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn);                                   
        } else if (i==9) {              
                  update_display();
                  lcd.setCursor(10, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==11) {              
                  update_display();
                  lcd.setCursor(13, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==13) {              
                  update_display();
                  lcd.setCursor(16, 1); 
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                      
        } else if (i==14) {              
                  update_display();
                  lcd.setCursor(17, 1);  
                  lcd.write(byte(0));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);
        } else if (i==3) {              
                  lcd.setCursor(1, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==5) {              
                  update_display();
                  lcd.setCursor(4, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==8) {              
                  update_display();
                  lcd.setCursor(8, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                     
        } else if (i==10){              
                  update_display();
                  lcd.setCursor(11, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                    
        } else if (i==12) {               
                  update_display();
                  lcd.setCursor(14, 1);  
                  lcd.write(byte(1));
                  lcd.write(byte(2));
                  notetrack = (midi_note_nums[currentBank][i-2]+transpose);
                  midiEventPacket_t noteOn = {0x09, 0x90 | 0, midi_note_nums[currentBank][i-2]+transpose, 60};  
                  MidiUSB.sendMIDI(noteOn);                                  
        } else if (i == 15) {                                                                                     // check for chord press button - button 15 to 18
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));  
                  note1track = (midi_chord_nums[currentBank][i-15]+transpose);                               // Displays the chord played based on the chord_chords array
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-15]+transpose, 60}; // Note 1 of Chord - NOTE # 0 of array
                  MidiUSB.sendMIDI(noteOn1);
                  note2track = (midi_chord_nums[currentBank][i-14]+transpose); 
                  delay(10);                                                                                      // Slight delay so next note of chord sounds properly (10ms)
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-14]+transpose, 60}; // Note 2 of Chord - NOTE # 1 of array
                  MidiUSB.sendMIDI(noteOn2);
                  note3track = (midi_chord_nums[currentBank][i-13]+transpose); 
                  delay(10);
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 60}; // Note 3 of Chord - NOTE # 2 of array
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 16) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));  
                  note1track = (midi_chord_nums[currentBank][i-13]+transpose);               
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-13]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn1);
                  delay(10);
                  note2track = (midi_chord_nums[currentBank][i-12]+transpose);   
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-12]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn2);
                  delay(10);
                  note3track = (midi_chord_nums[currentBank][i-11]+transpose);   
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i== 17) { // check for chord press button
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));   
                  note1track = (midi_chord_nums[currentBank][i-11]+transpose);                
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-11]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn1);
                  delay(10);
                  note2track = (midi_chord_nums[currentBank][i-10]+transpose); 
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-10]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn2);
                  delay(10);
                  note3track = (midi_chord_nums[currentBank][i-9]+transpose); 
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 60};
                  MidiUSB.sendMIDI(noteOn3);
        } else if (i == 18) { 
                  lcd.setCursor(8, 0);
                  lcd.print("Chord:" + String (chord_chords[currentBank][i-15]));      
                  note1track = (midi_chord_nums[currentBank][i-9]+transpose);             
                  midiEventPacket_t noteOn1 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-9]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn1);
                  delay(10);
                  note2track = (midi_chord_nums[currentBank][i-8]+transpose); 
                  midiEventPacket_t noteOn2 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-8]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn2);
                  delay(10);
                  note3track = (midi_chord_nums[currentBank][i-7]+transpose); 
                  midiEventPacket_t noteOn3 = {0x09, 0x90 | 0, midi_chord_nums[currentBank][i-7]+transpose, 60}; 
                  MidiUSB.sendMIDI(noteOn3);
        } 
     } else if (buttons[i].rose()) { // Check if button rose
           //update_display();         // update the display
           lcd.setCursor (0,1);
           lcd.print ("                  ");
           midiEventPacket_t noteOff = {0x08, 0x80 | 0, notetrack, 0};      // if note button rose, turn off note
           MidiUSB.sendMIDI(noteOff);
           delay(10);
           midiEventPacket_t noteOff1 = {0x08, 0x80 | 0, note1track, 0};    // if chord button rose, turn off note 1 of chord
           MidiUSB.sendMIDI(noteOff1);
           delay(10);
           midiEventPacket_t noteOff2 = {0x08, 0x80 | 0, note2track, 0};    // if chord button rose, turn off note 2 of chord
           MidiUSB.sendMIDI(noteOff2);
           delay(10);
           midiEventPacket_t noteOff3 = {0x08, 0x80 | 0, note3track, 0};    // if chord button rose, turn off note 3 of chord
           MidiUSB.sendMIDI(noteOff3);
           notetrack = 0;
           note1track = 0;
           note2track = 0;
           note3track = 0;
          } 
  }               
}