Joystick library slowing everything down

Hi everyone,
I successfully made a flight sim throttle, and now I am adding a radio.
I am using one Arduino Leonardo board for both the throttle and the radio.
My code uses up 45% of program storage space.
At the very bottom of my code, I have Joystick.setThrottle(throttle); Joystick.setYAxis(flap); Joystick.setXAxis(mix);
For some reason, this adds about a one second delay to everything else.
When I commented it out, everything worked at its normal speed.
I have no delay(); in any of my code.
Any ideas?

Maybe only send the joystick when values change and not every time round loop.

Good idea!
I'll try it and see what happens.

Has it occurred to you that we can't see your code?

You were right!
It woks a lot better now.
Thanks!

An interesting side note: Joystick.setButton(); does not seem to slow anything down.

Has it occurred to you that we can't see your code?

I can show my code, but I am actively changing the Joystick.setButton(); values around to satisfy MSFS2020's desires. in other words, I am still in the debugging process.

#include <LiquidCrystal_I2C.h>
#include <Joystick.h>

#define THROTTLE_MIN 789
#define THROTTLE_MAX 1023
#define THROTTLE_SWING 234
#define THROTTLE_PRECISION  2

#define FLAP_MIN 938
#define FLAP_MAX 474
#define FLAP_SWING 464
#define FLAP_PRECISION  10

#define MIX_MIN 612
#define MIX_MAX 859
#define MIX_SWING 247
#define MIX_PRECISION  2

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2);

//////////////////////////////////////////////////////////trottle
int throttle = A2;
int prevThrot = 0;
int flap = A4;
int prevFlap = 0;
int mix = A3;
int prevMix = 0;
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_MULTI_AXIS, 12, 0,
                   true, true, false, false, false, false,
                   false, true, false, false, false);

////////////////////////////////////////////////////////Radio
int swapcom = 0;
int swaptun = 0;//swaptun switches input between comm and nav
bool swapcomprs = false;
bool swaptunprs = false;
int x = 0;
float y = 0;
float freq[4] = {123.450, 111.45, 118.120, 109.45};
int afreq = 2;
int top = 1;
int xplus = 0;
int xmins = 0;
int yplus = 0;
int ymins = 0;


//////////////////////////////////////////////////////////

void setup() {
  Serial.begin(9600);

  pinMode(throttle, INPUT);
  pinMode(flap, INPUT);
  pinMode(mix, INPUT);

  Joystick.setThrottleRange(0, 100);
  Joystick.setThrottle(50);
  Joystick.setYAxisRange(0, 100);
  Joystick.setYAxis(0);
  Joystick.setXAxisRange(0, 100);
  Joystick.setXAxis(0);

  Joystick.begin(true);
  ////////////////////////////////////////////////////////
  lcd.begin(16, 2);
  lcd.init();
  lcd.clear();
  lcd.backlight();



}

void loop() {

  prevThrot = throttle;
  prevFlap = flap;
  prevMix = mix;
  
  throttle = analogRead(A2);
  flap = analogRead(A4);
  mix = analogRead(A3);

  //calibrating the pots
  throttle -= THROTTLE_MIN;
  throttle *= 100;
  throttle /= THROTTLE_SWING;
  throttle += 1;
  throttle -= throttle % THROTTLE_PRECISION;

  flap -= FLAP_MIN;
  flap *= -100;
  flap /= FLAP_SWING;
  flap += 1;
  flap -= flap % FLAP_PRECISION;

  mix -= MIX_MIN;
  mix *= 100;
  mix /= MIX_SWING;
  mix += 1;
  mix -= mix % MIX_PRECISION;

  /////////////////////////////////////////Radio
  swaptun = digitalRead(4);//switch between com and nav
  swapcom = digitalRead(5);//swap comms
  x = analogRead(A0);
  y = analogRead(A1);

  xmins = 0;
  xplus = 0;
  ymins = 0;
  yplus = 0;
  ////////////////////////////////////////fine tuning the joystick (will be a concentric encoder in future)
  if (x < 520) {
    x = -1;
    xmins = 1;
  } else if (x > 525 && x < 1024) {
    x = 1;
    xplus = 1;
  } else if (x > 520 && x < 525) {
    x = 0;
  }

  if (y < 510) {
    y = -0.005;
    ymins = 1;

  } else if (y > 520) {
    y = 0.005;
    yplus = 1;
  } else if (y > 510 && y < 520) {
    y = 0;
  }
  ////////////////////////////////////////JP's thing SUPER IMPORTANT
  top &= (((afreq & 1) ^ 1) << 1) | afreq & 1;
  top |= (afreq & 2) >> ((afreq & 1) ^ 1);
  ////////////////////////////////////////button pressing
  if (swapcom == 1) {
    swapcomprs = true;
  } else if (swapcomprs) {
    swapcomprs = false;

    afreq ^= 2;
    afreq &= 3;

  }
  if (swaptun == 1) {
    swaptunprs = true;
  } else if (swaptunprs) {
    swaptunprs = false;
    afreq ^= 1;
    afreq &= 3;

  }
  ///////////////////////////////////////////

  if (afreq == 1 || afreq == 3) { //nav side ommits the third decimal place.
    y *= 10;
  }

  freq[afreq] += (x + y);
  //////////////////////////////////////////rolls over @ 118 & 136.975
  //nav side needs to roll over @ 108 & 117.95
  //nav side also needs to omit the third place
  //if (afreq == 0 || afreq == 2) {
  if ((afreq & 1) == 0) {
    if (freq[afreq] > 136.975) {
      freq[afreq] = 118;
    } else if (freq[afreq] < 118) {
      freq[afreq] = 136.975;
    }
  } else {
    if (freq[afreq] > 117.95) {
      freq[afreq] = 108;
    } else if (freq[afreq] < 108) {
      freq[afreq] = 117.95;
    }
  }


  

  //printing averything to the LCD.
  lcd.setCursor(0, (top & 1) ^ 1);
  lcd.print(freq[0], 3);

  lcd.setCursor(9, ((top >> 1) & 1) ^ 1);
  lcd.print(freq[1]);

  lcd.setCursor(0, (top & 1));
  lcd.print(freq[2], 3);


  lcd.setCursor(9, ((top) >> 1) & 1);
  lcd.print(freq[3]);
  ///////////////////////////////////////little arrow;
  lcd.setCursor(7, 1);
  if (afreq & 1) {

    lcd.print(" >");
    Joystick.setButton(11, swapcomprs);
    Joystick.setButton(7, xplus);
    Joystick.setButton(8, xmins);
    Joystick.setButton(9, yplus);
    Joystick.setButton(10, ymins);
  } else {

    lcd.print("< ");
    Joystick.setButton(1, swapcomprs);
    Joystick.setButton(3, xplus);
    Joystick.setButton(4, xmins);
    Joystick.setButton(5, yplus);
    Joystick.setButton(12, ymins);
  }
  
  Joystick.setButton(2, swaptunprs);
  //////////////////////////////////////////END RADIO

  // send it to the sim only if changed
  if (prevThrot != throttle) {
    Joystick.setThrottle(throttle);
  } else if (flap != prevFlap) {
    Joystick.setYAxis(flap);
  } else if (mix != prevMix) {
    Joystick.setXAxis(mix);
  }
  
  

  

  /*Serial.println(swapcomprs);
    Serial.println(swaptunprs);
    Serial.println(xplus);
    Serial.println(xmins);
    Serial.println(yplus);
    Serial.println(ymins);*/


}