Joystick mouse moving on its own

thank you, will do!! one last question, the mouse movement is quite slow, do you know anyway I can add a variable to set the speed at which the mouse moves?

It looks like these lines

  int deltaX = map(offsetX, 2048, -2048, 5, -5);
  int deltaY = map(offsetY, 2048, -2048, 5, -5);
  if (deltaX != 0 || deltaY != 0) {
    Mouse.move(deltaX, deltaY);

set the maximum change each step makes.

Change 5 out for larger numbers to go faster, make then less than 5 to go slow.


  int deltaX = map(offsetX, 2048, -2048, rate, -rate);
  int deltaY = map(offsetY, 2048, -2048, rate, -rate);
  if (deltaX != 0 || deltaY != 0) {
    Mouse.move(deltaX, deltaY);

and somewhere up top

const byte rate = 7;   // speed control

a7

It's as @alto777 posted.

Something to consider:

A mouse goes certain steps in x and y axis relative to its actual position.

An analog joystick provides values that represent a certain x,y coordinate in a fixed coordinate system. It usually uses potentiometers.

Digital joystick only provide a direction, either only four (left, right, up, down) or eight (as before plus left up, left down, right up, right down). In both cases if none of those states has been detected the joystick is in a centered position. These joysticks use buttons or any other technology that provides binary data (on/off).

You can use analog or digital joysticks to emulate a mouse but

  • Digital provide only direction, not speed. If you want e.g. accelerated movement you have to use the time the stick is held in a certain direction to increase the steps per second.
  • With an analog joystick you can use its deflection directly to calculate the steps to go (your deltas).

So depending on your hardware you get different inputs!