Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the movement of an air mouse #23

Open
Tonymazzz opened this issue Jun 17, 2021 · 0 comments
Open

Improve the movement of an air mouse #23

Tonymazzz opened this issue Jun 17, 2021 · 0 comments

Comments

@Tonymazzz
Copy link

Tonymazzz commented Jun 17, 2021

Hello dear Asukiaaa, first of all congratulate you for this great library that you have provided us !!!
I have used it to create an Air mouse with mpu9250 and it works great but I know that the movement could still be improved a little more, for example, the movements are linear, it means that it is easier to draw a square than a circles, I do not know if I explain myself ...

On the other hand, in this code that I send you, I only use the gyroscope, since I don't know how to implement the accelerometer and magnetometer so that the accelerometer, gyroscope and magnetometer compensate each other and correct any drift that may occur.

And last, its there any autocalibration for the gyro and the accel when the Arduino start?
Or do i have to implement it with any code?

Any help or advice you can provide will be of great help dear Asukiaaa.

Thanks in advance :)

ARDUINO SKETCH

#include <MPU9250_asukiaaa.h>
#include <Mouse.h>

#define SDA_PIN 21
#define SCL_PIN 22
#define A18_PIN 16
#define A19_PIN 17 //STOP MOUSE MOVEMENT WHILE HOLDING

MPU9250_asukiaaa mySensor;

float aX, aY, aZ, aSqrt, gX, gY, gZ, mDirection, mX, mY, mZ;

int vx, vy;

void setup() {

Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);

pinMode (A18_PIN, INPUT_PULLUP);
pinMode (A19_PIN, INPUT_PULLUP);

mySensor.beginGyro();

Mouse.begin();

}

void loop() {

if (digitalRead(A19_PIN) == HIGH) {

mySensor.gyroUpdate();
gX = mySensor.gyroX();
//gY = mySensor.gyroY();
gZ = mySensor.gyroZ();

vx = (gX + 0) / 5;
vy = (gZ + 0) / 5;

Mouse.move(-vx, -vy);

}

{
if (digitalRead(A18_PIN) == HIGH) {
Mouse.press(MOUSE_LEFT);

} else {

Mouse.release(MOUSE_LEFT);
    }

 }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant