Controlling mouse using rotatry encoders

Hello Everyone,

I am trying to control the mouse with too rotary encoders to use as interface for a video game.

As for now it works, but i have a linearity problem with it.

I realized that depending on the speed of rotation the mouse doesn't move the same amount.
With a quick rotating speed the mouse moves way more than with a slower speedfor the same angular change of the encoder.

Here is the code I have been using :

timePassed = millis() - timeStampEnd;
xPassed = xStampEnd - pulsesX;
yPassed = pulsesY - yStampEnd;

moveX =  xPassed / timePassed;
moveY =  yPassed / timePassed;

Mouse.move (moveX, moveY);

xStampEnd = pulsesX;
yStampEnd = pulsesY;
timeStampEnd = millis();

Does anybody have a clue about what is wrong?

Thanks!

Are you asking about a mouse or are you asking about the cursor on your computer screen?

Paul

Paul_KD7HB:
Are you asking about a mouse or are you asking about the cursor on your computer screen?

Paul

Hi Paul,

Sorry for not being specific. I meant the mouse cursor.
For exemple if I rotate the encoder 180° slowly the mouse cursor will move lets say 1/4 of the screen, but if doing the same 180° quickly it will move 3/4 of the screen.

Here in the code pulsesX and pulsesY are the encoders inputs (position values, not speed).

Thx

Cedric

You have explicitly coded it to respond more to faster movement by dividing by time - just use xPassed and yPassed directly.

Thanks Mark,

I corrected the code using only those parameters, but still had the problem.

Just found out that it is in fact the mouse acceleration parameters on my OS that was doing that.
After using a utility to set the mouse acceleration it now works perfectly.

Thx for your help!