Arduino due program

Hello everyone,
I hope everyone are doing well. I wrote a due program code in that I am using six oleds sh1106 connected three oleds seperately to tc9548a 12c multiplexer and connected remaining three oleds to another tc9548a i2c multiplexer. The reason I why I am using two i2c multiplexer I will add more oleds in future. In the following code you can see in the loop 6 types of up and down counters and two toggle switch using push buttons. The output of the 6 counters are displayed in the six oleds.
The code which I had written works well. But I am noticing speed of the counters reducing decreasing when I am adding more oled. can you guys help me to increase the speed of the code.


const int buzzer=2;
const int buttonPin1 = 22, buttonPin2 = 23;
const int cutting_button = 34;    
const int nlcl=40;
const int lcl=41;

int cutter_State = 0;
int prestate=0;
int cut_mode=0;

const int buttonPin3 = 24, buttonPin4 = 25;  
int button3_State = 0, button4_State = 0; 
int suction_value =0;

const int offair=42;
const int onair=43;
const int airing_button = 35;    
int air_State = 0;
int prestate2=0;
int air_mode=0;



int button1_State = 0, button2_State = 0; 
signed long cut_value =0;


const int buttonPin5 = 26, buttonPin6 = 27;  
int button5_State = 0, button6_State = 0; 
int air_value =0;

const int buttonPin7 = 46, buttonPin8 = 47;  
int button7_State = 0, button8_State = 0; 
int inj_value =0;

const int buttonPin9 = 30, buttonPin10 = 31;  
int button9_State = 0, button10_State = 0; 
int ext_value =0;

const int buttonPin11 = 32, buttonPin12 = 33;  
int button11_State = 0, button12_State = 0; 
int dia_value =0;
#include "SparkFun_External_EEPROM.h" //add sam3x8e file
ExternalEEPROM myMem;


#include <Adafruit_GFX.h>
#include <Fonts/FreeSansBoldOblique9pt7b.h>
#include <Fonts/FreeSansBoldOblique12pt7b.h>
#include <Fonts/FreeSansBoldOblique18pt7b.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET 4
Adafruit_SH1106 display0(OLED_RESET);
Adafruit_SH1106 display1(OLED_RESET);
Adafruit_SH1106 display2(OLED_RESET);
Adafruit_SH1106 display3(OLED_RESET);
Adafruit_SH1106 display4(OLED_RESET);
Adafruit_SH1106 display5(OLED_RESET);



// Select I2C BUS
void TCA9548B(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
   Wire.beginTransmission(0x71);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
}

void TCA9548A(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
  Wire.beginTransmission(0x71);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
}
void setup() {
  
  Wire.begin();
  Wire.setClock(400000L);
  myMem.begin();
  myMem.setMemorySize(512000/8); //In bytes. 512kbit = 64kbyte
  myMem.setPageSize(128); //In bytes. Has 128 byte page size.
  myMem.enablePollForWriteComplete(); //Supports I2C polling of write completion
  myMem.setPageWriteTime(50); //3 ms max write time
  cut_value = myMem.get(10, cut_value); 
  suction_value = myMem.get(20, suction_value);   
  ext_value = myMem.get(50, ext_value); 
  air_value = myMem.get(30, air_value); 
  inj_value = myMem.get(40, inj_value); 
  dia_value = myMem.get(60, dia_value); 

   pinMode( buttonPin1, INPUT);
   pinMode(buttonPin2, INPUT);
  
   pinMode(buzzer,OUTPUT);
   pinMode(cutting_button, INPUT);
   pinMode(nlcl,OUTPUT);
   pinMode(lcl,OUTPUT);
  
   
   pinMode(buttonPin3, INPUT);
   pinMode(buttonPin4, INPUT);
  

   pinMode(offair,OUTPUT);
   pinMode(onair,OUTPUT);
   pinMode(airing_button, INPUT);

  
   pinMode(buttonPin5, INPUT);
   pinMode(buttonPin6, INPUT);
   pinMode(buttonPin7, INPUT);
   pinMode(buttonPin8, INPUT);
   pinMode(buttonPin9, INPUT);
   pinMode(buttonPin10, INPUT);
   pinMode(buttonPin11, INPUT);
   pinMode(buttonPin12, INPUT);

  
 
  DisplayInit();
  extra();
  
}

void extra(){
    for (int i = 0; i < 8; i++) {
    TCA9548A(i);   // Loop through each connected displays on the I2C buses  
    
    display0.begin();
  
    display1.begin();
   
    display2.begin();
   
    display3.begin();
 
    display4.begin();
 
    display5.begin();
    }
}
void DisplayInit(){
    for (int j = 0; j < 8; j++) {
   TCA9548B(j);   // Loop through each connected displays on the I2C buses  
    
   display0.begin();
  
   display1.begin();
  
   display2.begin();
 
   display3.begin();
 
   display4.begin();
 
    display5.begin();
    }
}
void loop() {

 
  cut_push();
  air_push();
  cutter_button();
  suction_button();
  air_button();
  inj_button();
  extr_button();
  dia_button();
  

   one();
   two();
   three();
   four();
   five();
   six();  

}
 
void one(){ 
   TCA9548A(1); 
     
    display0.fillRect(0,0,127,63,0);
    display0.drawRect(0,0,127,63,1);
   
  
    display0.setFont(&FreeSansBoldOblique12pt7b);           
    display0.setTextColor(1);
    display0.setCursor(8,22);
    display0.println("CUTTING");
    display0.setFont(&FreeSansBoldOblique18pt7b);          
    display0.setTextColor(1); 
    display0.setCursor(25,52);
    display0.println(cut_value); 

    display0.display();  
   
  }

void two(){
    TCA9548A(2); 
   display1.fillRect(0,0,127,63,0);
   display1.drawRect(0,0,127,63,1);

   
    display1.setFont(&FreeSansBoldOblique12pt7b);         
    display1.setTextColor(1);
    display1.setCursor(10,22);
    display1.println("SUCTION");


    display1.setFont(&FreeSansBoldOblique18pt7b);            
    display1.setTextColor(1); 
    display1.setCursor(30,52);
    display1.println(suction_value); 
    display1.display();   }  

 void three(){
 TCA9548A(3);

    display2.fillRect(0,0,127,63,0);
    display2.drawRect(0,0,127,63,1);
   
    display2.setFont(&FreeSansBoldOblique12pt7b);            
    display2.setTextColor(1);
    display2.setCursor(40,22);
    display2.println("AIR");
    display2.setFont(&FreeSansBoldOblique18pt7b);            
    display2.setTextColor(1); 
    display2.setCursor(30,52);
    display2.println(air_value);
   
  
   display2.display(); }

   void three1(){
    TCA9548A(3);

   display2.fillRect(0,0,127,63,0);
   display2.drawRect(0,0,127,63,1);
   
   display2.setFont(&FreeSansBoldOblique12pt7b);            
   display2.setTextColor(1);
   display2.setCursor(40,22);
   display2.println("AIR");
   display2.setFont(&FreeSansBoldOblique18pt7b);           
    display2.setTextColor(1); 
    display2.setCursor(30,52);
    display2.println("air_mode");
   
  
   display2.display();}
 void four(){
  TCA9548B(0);
 
  display3.fillRect(0,0,127,63,0);
   display3.drawRect(0,0,127,63,1);
     display3.setFont(&FreeSansBoldOblique9pt7b);           
    display3.setTextColor(1);
    display3.setCursor(15,16);
    display3.println("INJECTION");
     display3.setFont(&FreeSansBoldOblique18pt7b);             
    display3.setTextColor(1); 
    display3.setCursor(45,52);
    display3.println(inj_value); 
    display3.display();  }
 void five(){
   TCA9548B(7);
  
  display4.fillRect(0,0,127,63,0);
   display4.drawRect(0,0,127,63,1);
   display4.setFont(&FreeSansBoldOblique9pt7b);             
    display4.setTextColor(1);
    display4.setCursor(5,16);
    display4.println("EXTRACTION");
    display4.setFont(&FreeSansBoldOblique18pt7b);           
    display4.setTextColor(1); 
    display4.setCursor(30,52);
    display4.println(ext_value); 
    display4.display(); 
    }
void six(){
   TCA9548B(4);
  
   display5.fillRect(0,0,127,63,0);
   display5.drawRect(0,0,127,63,1);
   
   display5.setFont(&FreeSansBoldOblique12pt7b);            
   display5.setTextColor(1);
   display5.setCursor(40,22);
   display5.println("DIA");
   display5.setFont(&FreeSansBoldOblique18pt7b);           
    display5.setTextColor(1); 
    display5.setCursor(40,52);
    display5.println(dia_value); 
    display5.display();
    }
  


void cutter_button(){   
  myMem.put(10, cut_value);
  button1_State = digitalRead(buttonPin1);
  button2_State = digitalRead(buttonPin2);
  // counter increment if the pushbutton 1 is pressed.
  if (button1_State == HIGH && cut_value<6000) {
    cut_value+=60;

  digitalWrite(buzzer, 255);
   delay(30);
   digitalWrite(buzzer,0);

    
    
  }

   else if (button2_State == HIGH  && cut_value>=1) {
     cut_value-=60;
  
 digitalWrite(buzzer, 255);
 delay(30);
 digitalWrite(buzzer,0);

     
 
  } 
  else if (cut_value<0){
    cut_value =0;
   
     }}
void suction_button() {
   
   myMem.put(20, suction_value); 
  // read the state of the pushbutton
  button3_State = digitalRead(buttonPin3);
  button4_State = digitalRead(buttonPin4);
  // counter increment if the pushbutton 1 is pressed.
  if (button3_State == HIGH && suction_value<650) {
    suction_value+=10;
    
    digitalWrite(2, 255);
     delay(30);
    digitalWrite(2,0);

    
    
  }

   else if (button4_State == HIGH  && suction_value>=1) {
     suction_value-=10;
     
    digitalWrite(2, 255);
     delay(30);
    digitalWrite(2,0);
     
 
  } 
  else if (suction_value<0){
    suction_value =0;
   
     }
 
}
void air_button(){
   myMem.put(30, air_value); 
 
  button5_State = digitalRead(buttonPin5);
  button6_State = digitalRead(buttonPin6);
 if (button5_State == HIGH && air_value<300) {
    air_value+=1;
    
   digitalWrite(2, 255);
    delay(30);
   digitalWrite(2,0);
   
    
    
  }

   else if (button6_State == HIGH  && air_value>=1) {
     air_value-=1;
     
    digitalWrite(2, 255);
   delay(30);
   digitalWrite(2,0);


  } 
 else if (air_value<0){
    air_value =0;
   
     }
  }
void inj_button(){
  
  myMem.put(40, inj_value);
  button7_State = digitalRead(buttonPin7);
  button8_State = digitalRead(buttonPin8);
 if (button7_State == HIGH && inj_value<7) {
    inj_value+=1;
    
   digitalWrite(2, 255);
    delay(30);
   digitalWrite(2,0);    
  }

   else if (button8_State == HIGH  && inj_value>=1) {
     inj_value-=1;
   digitalWrite(2, 255);
    delay(30);
    digitalWrite(2,0);
  } 
 else if (inj_value<0){
    inj_value =0;
   
     }
  }

void extr_button(){
    
 myMem.put(50, ext_value); 
  button9_State = digitalRead(buttonPin9);
  button10_State = digitalRead(buttonPin10);
 if (button9_State == HIGH && ext_value<650) {
    ext_value+=10;
    
 digitalWrite(2, 255);
  delay(30);
 digitalWrite(2,0);
    
  }

   else if (button10_State == HIGH  && ext_value>=1) {
     ext_value-=10;
     
   digitalWrite(2, 255);
    delay(30);
   digitalWrite(2,0);

  } 
 else if (ext_value<0){
    ext_value =0;
   
     }
  
  }
void dia_button(){

  myMem.put(60, dia_value); 
  button11_State = digitalRead(buttonPin11);
  button12_State = digitalRead(buttonPin12);
 if (button11_State == HIGH && dia_value<30) {
    dia_value+=1;
    
  digitalWrite(2, 255);
  delay(30);
  digitalWrite(2,0);
   
 
  }

   else if (button12_State == HIGH  && dia_value>=1) {
     dia_value-=1;
     
   digitalWrite(2, 255);
   delay(30);
  digitalWrite(2,0);

   
 
  } 
 else if (dia_value<0){
    dia_value =0;
   
     }
  }
void cut_push(){
   cutter_State = digitalRead(cutting_button);
 if (cutter_State == HIGH && cut_mode<2&&prestate==0) {
    cut_mode+=1;  
    digitalWrite(2, HIGH);
     delay(100);
    digitalWrite(2,0);
    prestate=1;  
    
  }
  else if (cutter_State == LOW){
   
    prestate=0;
   
     }
  else if (cut_mode>1){
    
    cut_mode=0;
    }
  if(cut_mode==0){
    digitalWrite(nlcl,HIGH);
    digitalWrite(lcl,LOW);
    }
  if(cut_mode==1){
    digitalWrite(nlcl,LOW);
    digitalWrite(lcl,HIGH);
    }
  }
  void air_push(){

  air_State = digitalRead(airing_button);
 if (air_State == HIGH && air_mode<2&&prestate2==0) {
    air_mode+=1;
   digitalWrite(2, HIGH);
   delay(100);
    digitalWrite(2,0);
    prestate2=1;  
    
  }
  else if (air_State == LOW){
   
    prestate2=0;
   
     }
  else if (air_mode>1){
    air_mode=0;
    }
   if(air_mode==0){
    digitalWrite(offair,HIGH);
    digitalWrite(onair,LOW);
    }
  if(air_mode==1){
    digitalWrite(offair,LOW);
    digitalWrite(onair,HIGH);
    }
 
  }


 

note: I am additionally using 24c512 eeprom to store the values.

Remove the delays

yes but It doesnt affect the speed normally the oleds response is low. Even if I remove the dealy there is no difference

Why not create a MRE (minimal representative example) without all the extraneous code that shows your problem and perhaps that will focus in on the problem.

Before moving on, I would recommend that you read about arrays and functions. You could put all your displays in array and goes throw it in a loop. But actually you just copied the same code 6 times. This is a very inefficient way of programming. Your program is long and ill adapted to change - each change needs to be repeated 6 times in the same procedures, it is very easy to make mistakes.

Do not touch every display in every cycle, update only those displays, which data is changed.

Addition - and even in case of updating - inside the display functions do not redraw all picture, update only line that display the value

Exactly, rule of thumb; if you are copy and pasting code with only minor changes multiple times then there is a better way.

can you kindly give example

Example for what?

how to array the display

Shortened example
Connect first three display to TCA9548A (0,1, 2) and next three to TCA9548B (0,1, 2)

#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <Fonts/FreeSansBoldOblique9pt7b.h>
#include <Fonts/FreeSansBoldOblique12pt7b.h>
#include <Fonts/FreeSansBoldOblique18pt7b.h>
#include <Wire.h>
#define OLED_RESET 4
// array of six SH1106 displays, each used OLED_RESET pin
Adafruit_SH1106 display[] = {OLED_RESET,OLED_RESET,OLED_RESET,OLED_RESET,OLED_RESET,OLED_RESET};

// not changed
void TCA9548B(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
   Wire.beginTransmission(0x71);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
}

void TCA9548A(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
  Wire.beginTransmission(0x71);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission(); 
}

void DisplayInit(){
    for (int j = 0; j < 3; j++) {
      TCA9548A(j);   // Loop through each connected displays on the I2C buses  
      display[j].begin();
     }
    for (int j = 3; j < 6; j++) {
      TCA9548B(j);   // Loop through each connected displays on the I2C buses  
      display[j].begin();
     }
}
void update_display(uint8_t num, char* heading, int value ){ 
   
    if (num <3) TCA9548A(num); 
    else TCA9548B(num-3);
     
    display[num].fillRect(0,0,127,63,0);
    display[num].drawRect(0,0,127,63,1);
   
  
    display[num].setFont(&FreeSansBoldOblique12pt7b);           
    display[num].setTextColor(1);
    display[num].setCursor(8,22);
    display[num].println(heading);
    display[num].setFont(&FreeSansBoldOblique18pt7b);          
    display[num].setTextColor(1); 
    display[num].setCursor(25,52);
    display[num].println(value); 

    display[num].display();  
   
  }
void setup() {
  Wire.begin();
  DisplayInit();
}

void loop() {
  int cut_value =22;  // dummy value, for example only
 // example of using update_display() function:
  update_display(0, "CUTTING", cut_value);
}

TYSM for your awesome help