MIDI and 7-Segment display not working simultaneously

Hi all. Super brand new to this, so please pardon my ignorance and messy code.

I'm modding a foot controller to use as a MIDI controller, and it came with a 7-segment display that I'm trying to get to work alongside everything. The idea is that one of the buttons changes the bank/patch of the controller (by basically shifting which notes the buttons play), while the 7-seg displays which bank/patch the controller is currently on.

I've gotten the MIDI implementation to work wonderfully, and managed to program one of the buttons to increment patches and loop back to the first patch without issue. For some reason however, when I include code to light up the display, the display lights up and changes as it should along with my patch changes but the MIDI completely stops working altogether.

Here's my code (remember, I'm new to this):

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

int button1 = 53; //button1 on digital pin 53
int button2 = 52; //button2 on digital pin 52
int button3 = 51; //button3 on digital pin 51
int button4 = 50; //button4 on digital pin 50
int button5 = 49; //button5 on digital pin 49
int button6 = 48; //button6 on digital pin 48
int button7 = 47; //button7 on digital pin 47
int button8 = 46; //button8 on digital pin 46
int button9 = 45; //button9 on digital pin 45
int button10 = 44; //button10 on digital pin 44
int button11 = 43; //button11 on digital pin 43

int segA = 34; //7-seg A on digital pin 34;
int segB = 35; //7-seg B on digital pin 35;
int segC = 36; //7-seg C on digital pin 36;
int segD = 37; //7-seg D on digital pin 37;
int segE = 38; //7-seg E on digital pin 38;
int segF = 39; //7-seg F on digital pin 39;
int segG = 40; //7-seg G on digital pin 40;


int button1beans = 0;
int button2beans = 0;
int button3beans = 0;
int button4beans = 0;
int button5beans = 0;
int button6beans = 0;
int button7beans = 0;
int button8beans = 0;
int button9beans = 0;
int button10beans = 0;
int button11beans = 0;

int button1state = 0; //these state values help us only sendmidi commands once for every button put
int button2state = 0; //bear in mind this will only be a problem if you plan on having lots of midi things going on at once
int button3state = 0; //it just stops clogging up the midi feed with constant midi off commands.
int button4state = 0; //as themore keys you send the more midi off commands are constantly being sent
int button5state = 0; //so this just neatens the midi stream a bit to prevent mistakes. 
int button6state = 0;
int button7state = 0;
int button8state = 0;
int button9state = 0;
int button10state = 0;
int button11state = 0;

int button10patch = 0; //cycle through patches


void setup()
{
  MIDI.begin();

pinMode(button1, INPUT_PULLUP); //wait to recieve ground to do something
pinMode(button2, INPUT_PULLUP); 
pinMode(button3, INPUT_PULLUP); 
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP); 
pinMode(button6, INPUT_PULLUP); 
pinMode(button7, INPUT_PULLUP); 
pinMode(button8, INPUT_PULLUP); 
pinMode(button9, INPUT_PULLUP); 
pinMode(button10, INPUT_PULLUP);
pinMode(button11, INPUT_PULLUP);

pinMode(segA,OUTPUT); //7-seg digital pins to output mode
pinMode(segB,OUTPUT);
pinMode(segC,OUTPUT);
pinMode(segD,OUTPUT);
pinMode(segE,OUTPUT);
pinMode(segF,OUTPUT);
pinMode(segG,OUTPUT);
  
}



void loop()
{

  button1beans = digitalRead(button1); //read status of button
  button2beans = digitalRead(button2);
  button3beans = digitalRead(button3);
  button4beans = digitalRead(button4);
  button5beans = digitalRead(button5);
  button6beans = digitalRead(button6);
  button7beans = digitalRead(button7);
  button8beans = digitalRead(button8);
  button9beans = digitalRead(button9);
  button10beans = digitalRead(button10);
  button11beans = digitalRead(button11); 



  if ((button10beans == LOW) && (button10state == 0)) //increment patch
  { 
    ++button10patch;
    button10state = 1;
  }
  if ((button10beans == HIGH) && (button10state == 1)) //clear button state upon button release
  { 
    button10state = 0;
  }
  if ((button10patch > 2)) //loop back to patch 0 after patch 2
  {
    button10patch = 0;
  }


  if((button10patch == 0)) //patch 0, first bank of notes
  {

    digitalWrite(segA,LOW); //show me 0 on 7-seg
    digitalWrite(segB,LOW);
    digitalWrite(segC,LOW);
    digitalWrite(segD,LOW);
    digitalWrite(segE,LOW);
    digitalWrite(segF,LOW);
    digitalWrite(segG,HIGH);

    if ((button1beans == LOW) && (button1state == 0)) //button push
    { MIDI.sendNoteOn(36,127,1); //MIDI note 36 on, velocity 127, channel 1
      button1state = 1;}  
    if ((button1beans == HIGH) && (button1state == 1)) //button release
    { MIDI.sendNoteOff(36,0,1); //MIDI note 36 off, velocity 0, channel 1
      button1state = 0;
    }  


    if ((button2beans == LOW) && (button2state == 0))
    { MIDI.sendNoteOn(37,127,1);
     button2state = 1;}  
    if ((button2beans == HIGH) && (button2state == 1))
    { MIDI.sendNoteOff(37,0,1);
      button2state = 0;
    }  
  
    if ((button3beans == LOW) && (button3state == 0))
    { MIDI.sendNoteOn(38,127,1);
     button3state = 1;}  
    if ((button3beans == HIGH) && (button3state == 1))
    { MIDI.sendNoteOff(38,0,1);
      button3state = 0;
    }  
  
    if ((button4beans == LOW) && (button4state == 0))
    { MIDI.sendNoteOn(39,127,1);
      button4state = 1;}  
    if ((button4beans == HIGH) && (button4state == 1))
    { MIDI.sendNoteOff(39,0,1); 
      button4state = 0;
    }  
  
    if ((button5beans == LOW) && (button5state == 0))
    { MIDI.sendNoteOn(44,127,1);
      button5state = 1;}  
    if ((button5beans == HIGH) && (button5state == 1))
    { MIDI.sendNoteOff(44,0,1);
      button5state = 0;
    }  
  
    if ((button6beans == LOW) && (button6state == 0))
    { MIDI.sendNoteOn(45,127,1);
      button6state = 1;}  
    if ((button6beans == HIGH) && (button6state == 1))
    { MIDI.sendNoteOff(45,0,1);
      button6state = 0;
    }  
  
    if ((button7beans == LOW) && (button7state == 0))
    { MIDI.sendNoteOn(46,127,1);
      button7state = 1;}  
    if ((button7beans == HIGH) && (button7state == 1))
    { MIDI.sendNoteOff(46,0,1);
      button7state = 0;
    }  
  
    if ((button8beans == LOW) && (button8state == 0))
    { MIDI.sendNoteOn(47,127,1); 
      button8state = 1;}  
    if ((button8beans == HIGH) && (button8state == 1))
    { MIDI.sendNoteOff(47,0,1);
      button8state = 0;
    }  
  
    if ((button9beans == LOW) && (button9state == 0))
    { MIDI.sendNoteOn(40,127,1); 
      button9state = 1;}  
    if ((button9beans == HIGH) && (button9state == 1))
    { MIDI.sendNoteOff(40,0,1);  
      button9state = 0;
    }  
  
    if ((button11beans == LOW) && (button11state == 0))
    { MIDI.sendControlChange(120,0,1); //cc 120 MIDI Panic, midi channel 1. 
      button11state = 1;}  
    if ((button11beans == HIGH) && (button11state == 1))
    {   
      button11state = 0; //back to 0?
    }
  }

I have a couple more "if" statements that correspond to the patch changes that are basically the same as the one included. Decided to leave them out for brevity. Also, the code was based on this project, which is why one of the variables is named "buttonXbeans". Just ignore that...

It seems like the issue lies in the setup, since when I remove the 7-segment pinMode commands from the code, I get MIDI working as normal again.

Thanks for the help!

EDIT: Forgot to mention I am using a MEGA 2560. No reason for that specific model, it was just what was available on Craigslist near me...

There's nothing that jumps out at me; pins 34 through 40 certainly have no obvious conflicts with Serial. I can't see why setting them to OUTPUT would have any effect.

Totally off the wall bonkers question: all your segments have appropriate current limiting resistors, right?

I have a bunch I plan to harvest from the foot controller's old motherboard but I don't have them installed right now. I figured those were more for protecting the display long-term and wouldn't interfere with signal as I'm poking around and prototyping code. There's a single 100 Ohm resistor on the common pin but the actual display pins are going directly to the Arduino as of now.

That is a potential issue. You are overloading the output pins and browning out the processor, and it's behaving oddly.

Try it with the 7 segment code in place, but no actual display. So all the code will be doing what it should, but there won't be any excess current consumption. See how that goes.

Found the issue. It was in fact a hardware problem, not something wrong with my code.

I stupidly thought I could connect the MIDI jack and the 7-seg to the same resistor connected to the 5V pin. Gave each common lead their own resistor and hey presto everything worked.

Did end up connecting those other resistors to the 7-seg display pins after that as well. Thanks for the assistance!