MIDI Controller with Arduino Uno

Evening all.

I am attempting to create a MIDI controller using an Arduino Uno board, which has 5 switches as inputs, with the hope of outputting MIDI code to be read on lighting control software. The lighting software accepts the MIDI input and sends a feedback signal with the same address to the controller to illuminate an LED. I am hoping to maybe do something like this too.

I’m new to this game so I’m just trying to borrow and adapt codes and guides found on the internet.

I have connected channels 8-12 to a push button each, and also to Gnd via an 11k resistor… The other side of each switch is connected to the 5v pin. This was previously confirmed to be wired correctly by a forum user. The MIDI output LEDs can be added later, the main bit is the MIDI controls at the moment.

I stumbled across a guide with a code for a 2 channel MIDI controller, which I previously attempted to modify to incorporate 5 channels. I have attempted this, posted about it and failed miserably previously, so this is really a begging request for help that someone might be able to put some sort of code together for me please? As an electrician I can get my head round the physical wiring bits, but I have accepted that I know nothing about programming!

The code below is the code I unsuccessfully attempted to modify.

#define LED 13    // LED pin on Arduino board
#define switch1 8              // 1st Switch
#define switch2 9               // 2nd Switch
#define switch3 10               // 3rd Switch
#define switch4 11               // 4th Switch
#define switch5 12               // 5th Switch
#define MIDI_COMMAND_CONTROL_CHANGE 0xB0
#define MIDI_COMMAND_NOTE_ON 0x90
#define MIDI_COMMAND_NOTE_OF 0x80


//Variables
int switch1LastState = 0;
int switch1CurrentState = 0;
int switch2LastState = 0;
int switch2CurrentState = 0;
int switch3LastState = 0;
int switch3CurrentState = 0;
int switch4LastState = 0;
int switch4CurrentState = 0;
int switch5LastState = 0;
int switch5CurrentState = 0;


// the format of the message to send Via serial 
typedef union {
    struct {
 uint8_t command;
 uint8_t channel;
 uint8_t data2;
 uint8_t data3;
    } msg;
    uint8_t raw[4];
} t_midiMsg;




void blinkLed(byte num) {  // Basic blink function
  for (byte i=0;i<num;i++) {
    digitalWrite(LED,HIGH);
    delay(50);
    digitalWrite(LED,LOW);
    delay(50);
  }
}


void setup() {
  pinMode(LED, OUTPUT);
  pinMode(switch1,INPUT);
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
  pinMode(switch4, INPUT);
  pinMode(switch5, INPUT);
  Serial.begin(115200);
  
  blinkLed(3);
}


void loop() {
  
t_midiMsg midiMsg1;  // MIDI message for Switch 1
t_midiMsg midiMsg2;  //MIDI message for Swtich 2
t_midiMsg midiMsg3;  //MIDI message for Swtich 3
t_midiMsg midiMsg4;  //MIDI message for Swtich 4
t_midiMsg midiMsg5;  //MIDI message for Swtich 5
switch1CurrentState = digitalRead(switch1);
switch2CurrentState = digitalRead(switch2);
switch3CurrentState = digitalRead(switch3);
switch4CurrentState = digitalRead(switch4);
switch5CurrentState = digitalRead(switch5);


if (switch1CurrentState == 1){
    if(switch1LastState == 0){
                  midiMsg1.msg.command = MIDI_COMMAND_CONTROL_CHANGE;
          midiMsg1.msg.channel = 1;
          midiMsg1.msg.data2   = 1;
          midiMsg1.msg.data3   = 0; /* Velocity */


          /* Send note on */
          Serial.write(midiMsg1.raw, sizeof(midiMsg1));                           
         blinkLed(2);           }
                                 }
switch1LastState = switch1CurrentState;


if (switch2CurrentState == 1){
    if(switch2LastState == 0){
                  midiMsg2.msg.command = MIDI_COMMAND_CONTROL_CHANGE;
          midiMsg2.msg.channel = 2;
          midiMsg2.msg.data2   = 2;
          midiMsg2.msg.data3   = 0; /* Velocity */


          /* Send note on */
          Serial.write(midiMsg2.raw, sizeof(midiMsg2));                            
         blinkLed(2);           }
                                 } 
    switch2LastState = switch2CurrentState;


if (switch3CurrentState == 1){
    if(switch3LastState == 0){
                  midiMsg3.msg.command = MIDI_COMMAND_CONTROL_CHANGE;
          midiMsg2.msg.channel = 3;
          midiMsg2.msg.data2   = 3;
          midiMsg2.msg.data3   = 0; /* Velocity */


          /* Send note on */
          Serial.write(midiMsg3.raw, sizeof(midiMsg3));                            
         blinkLed(2);           }
                                 } 
    switch3LastState = switch3CurrentState;


if (switch4CurrentState == 1){
    if(switch4LastState == 0){
                  midiMsg4.msg.command = MIDI_COMMAND_CONTROL_CHANGE;
          midiMsg4.msg.channel = 4;
          midiMsg4.msg.data2   = 4;
          midiMsg4.msg.data3   = 0; /* Velocity */


          /* Send note on */
          Serial.write(midiMsg4.raw, sizeof(midiMsg4));                            
         blinkLed(2);           }
                                 } 
    switch4LastState = switch4CurrentState;


if (switch5CurrentState == 1){
    if(switch5LastState == 0){
                  midiMsg5.msg.command = MIDI_COMMAND_CONTROL_CHANGE;
          midiMsg5.msg.channel = 5;
          midiMsg5.msg.data2   = 5;
          midiMsg5.msg.data3   = 0; /* Velocity */


          /* Send note on */
          Serial.write(midiMsg5.raw, sizeof(midiMsg5));                            
         blinkLed(2);           }
                                 } 
    switch5LastState = switch5CurrentState;
}

I verified and uploaded the code before, which brought up no errors, but when i tested it with Serial to Midi convertor, and MIDI-OX monitor software, I seemed to be getting nothing! The LED on pin 13 was flashing when I pressed the buttons so the board did seem to be responding, just not outputting any code.

Can anyone please offer any assistance?
Thanks in advance
Liam