Multiple sketches in Leonardo

I created a circuit board for 32 analog inputs using CD4021BE shift registers. I also have inputs for two joysticks. The axis connect to the analog inputs and the joystick switches connect to the digital inputs.

I know there is a better way to do this than all the if statements, but I haven't figured it out yet. I would like to be able to change the state of one of the 32 inputs to activate the joystick mouse control. Separately both sketches work great. When I start to integrate them, the joystick is very jerky and essentially not usable. I haven't created the if statement for the right mouse button yet. Once i get one joystick working well, I plan on copying the code and changing the variables to work for the second joystick.

I have attached my code due to character limits.

Test_1.ino.ino (9.91 KB)

  // if it's changed and it's high, toggle the mouse state:
  if (switchState == HIGH) {
    mouseIsActive = !mouseIsActive;
  }

That statement does NOT detect a change of the switch state.

I created a circuit board for 32 analog inputs using CD4021BE shift registers.

You misspelled digital...

When I start to integrate them, the joystick is very jerky

You don't suppose

that all

the delay()s

has anything

to do with

that, do you?