 void readmux(){//reads the 14 buttons, displays and sends midi comands through trs
int silvebutton;  
for(i = 0; i < 8; i++){ //sets count to advance mux address aray that sends addres to mux.
digitalWrite(SA0, BIN1[i]);
digitalWrite(SA1, BIN2[i]);
digitalWrite(SA2, BIN3[i]);
 
 int test1 = digitalRead(buttons1);//some how these 3 stabilize the button reads. don't know why?
 int test2 = digitalRead(buttons2);
 int test3 = digitalRead(buttons3);

if (digitalRead(buttons1) == 0){ //first mux
//to add togle method for (i.e. effect on 56 efect off 57) create flag system here to switch between two seperate array entries to be added also?
//fiure out togle code idea held in [5][14] mentioned in comment in array setup? may need array for true/false 1-14.
  TCA9548A(2);
  mainDisplay.clearDisplay();
  mainDisplay.setTextSize(1.5);
  mainDisplay.setTextColor(WHITE);
  mainDisplay.setCursor(20,2);
  mainDisplay.print("DESIGNERTRONICS");
  mainDisplay.setTextSize(2);
if(blueTooth==1){
    mainDisplay.setCursor(95,15);
    mainDisplay.print("BT");
}
  mainDisplay.setCursor(10,15);
  mainDisplay.print("BTN:");
  mainDisplay.setCursor(60,15);
  cmdtype = ("%d ", currentPreset[0][i]);//load in to cmtype to resolve NN NF CC PC below
  mainDisplay.println(i + 1);//button number, add 1 to resolve 0,1,2.. in array to button 1,2,3...
  mainDisplay.setCursor(15,40);
  mainDisplay.print(mType[cmdtype]);//NN NF CC PC
  mainDisplay.setCursor(40,40);
  mainDisplay.printf("%d ", currentPreset[2][i]);//note
  mainDisplay.setCursor(80,40);
  mainDisplay.printf("%d ", currentPreset[3][i]);//velocity
       mainDisplay.display();

 switch (currentPreset[0][i]){// midi message type held in aray space 0, cmd type- NN NF CC PC
case 0:
   // cmd type, note number , velocity , channel 
    if(blueTooth==1){BMIDI.sendNoteOn( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);}
                else{MIDI.sendNoteOn( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);}
     break;       
case 1:
    if(blueTooth==1){BMIDI.sendNoteOff( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);} 
                else{MIDI.sendNoteOff( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);}
    break;        
case 2: 
    // controller number (7 = Volume), value (100), channel (1)   
    if(blueTooth==1){BMIDI.sendControlChange( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);}
                else{MIDI.sendControlChange( currentPreset[2][i],currentPreset[3][i],currentPreset[1][i]);}
    break;        
case 3:
    // program number (10), channel (1)    
    if(blueTooth==1){BMIDI.sendProgramChange( currentPreset[2][i],currentPreset[1][i] );}
                else{MIDI.sendProgramChange( currentPreset[2][i],currentPreset[1][i] );}
    break; 
}//endswitch
delay(250);

   }
if (digitalRead(buttons2) == 0){//second mux
  
  TCA9548A(2);
  mainDisplay.clearDisplay();
  mainDisplay.setTextSize(1.5);
  mainDisplay.setTextColor(WHITE);
  mainDisplay.setCursor(20,2);
  mainDisplay.print("DESIGNERTRONICS");
  mainDisplay.setTextSize(2);
if(blueTooth==1){
    mainDisplay.setCursor(95,15);
    mainDisplay.print("BT");
}
  mainDisplay.setCursor(10,15);
  mainDisplay.print("BTN:");
  mainDisplay.setCursor(60,15);
  cmdtype = ("%d ", currentPreset[0][i+8]);//load in to cmtype to resolve NN NF CC PC below
  mainDisplay.println(i + 9);//add 1 to resolve 0,1,2.. in array to button 1,2,3...
  mainDisplay.setCursor(15,40);
  mainDisplay.print(mType[cmdtype]);
  mainDisplay.setCursor(40,40);
  mainDisplay.printf("%d ", currentPreset[2][i+8]);
  mainDisplay.setCursor(80,40);
  mainDisplay.printf("%d ", currentPreset[3][i+8]);
       mainDisplay.display();

switch (currentPreset[0][i+8]){//array midi message type held in 0
case 0:
if(blueTooth==1){BMIDI.sendNoteOn( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);} 
             else{MIDI.sendNoteOn( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);}
    break;       
case 1:
    
if(blueTooth==1){BMIDI.sendNoteOff( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);}
             else{MIDI.sendNoteOff( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);}
    break;
    break;        
case 2: 
    
if(blueTooth==1){BMIDI.sendControlChange( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);}
             else{MIDI.sendControlChange( currentPreset[2][i+8],currentPreset[3][i+8],currentPreset[1][i+8]);}
    break;        
case 3:
   
if(blueTooth==1){BMIDI.sendProgramChange( currentPreset[2][i+8],currentPreset[1][i+8]);}
             else{MIDI.sendProgramChange( currentPreset[2][i+8],currentPreset[1][i+8]);}
    break; 
}//endswitch

delay(250);
  }
if (digitalRead(buttons3) == 0){//third mux
   
  TCA9548A(2);
  mainDisplay.clearDisplay();
  mainDisplay.setTextSize(1.5);
  mainDisplay.setTextColor(WHITE);
  mainDisplay.setCursor(20,2);
  mainDisplay.print("DESIGNERTRONICS");
  mainDisplay.setTextSize(2);
if(blueTooth==1){
    mainDisplay.setCursor(95,15);
    mainDisplay.print("BT");
}
  mainDisplay.setCursor(10,15);
  mainDisplay.print("BTN:");
  mainDisplay.setCursor(60,15);
 cmdtype = ("%d ", currentPreset[0][i+16]);//load in to cmtype to resolve NN NF CC PC below
  mainDisplay.println(i + 17);//add 1 to resolve 0,1,2.. in array to button 1,2,3...
  mainDisplay.setCursor(15,40);
  mainDisplay.print(mType[cmdtype]);
  mainDisplay.setCursor(40,40);
  mainDisplay.printf("%d ", currentPreset[2][i+16]);
  mainDisplay.setCursor(80,40);
  mainDisplay.printf("%d ", currentPreset[3][i+16]);
       mainDisplay.display();

switch (currentPreset[0][i+16]){//array midi message type held in 0
case 0:
if(blueTooth==1){BMIDI.sendNoteOn( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);} 
             else{MIDI.sendNoteOn( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);}
    break;       
case 1:
    
if(blueTooth==1){BMIDI.sendNoteOff( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);}
             else{MIDI.sendNoteOff( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);}
    break;
    break;        
case 2: 
    
if(blueTooth==1){BMIDI.sendControlChange( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);}
             else{MIDI.sendControlChange( currentPreset[2][i+16],currentPreset[3][i+16],currentPreset[1][i+16]);}
    break;        
case 3:
   
if(blueTooth==1){BMIDI.sendProgramChange( currentPreset[2][i+16],currentPreset[1][i+16]);}
             else{MIDI.sendProgramChange( currentPreset[2][i+16],currentPreset[1][i+16]);}
    break; 
}//endswitch

delay(250); 
   }

}//for end
}//end readmux
 