I am using an acceleormeter mpu6050 with my Arduino Uno to make an accellerometer controlled mouse.
I have the acclerometer values in the x, y and z directions. I need to calculate the distance travelled by the accelerometer and convert it to coordinates for my mouse pointer.
void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int vx = map(ax, -20000, 20000, 90, -90);
int vy = map(ay, -20000, 20000, 90, -90);
myconnection.println(vx);
myconnection.println(vy);
delay(10);
//processclick();
}
I am using the getMotion() function to get the acceleration in x and y direction every 10ms.
What I need to do now is the detect a change in the acceleration in x or y direction and after calculating the distance travelled change the mouse pointer location using another program.
I am unable to find any source that would tell me how to do that. Please let me know how the distance can be calculated. For now i only want the updated cursor position and will factor in the mouse angle later.
Thank you in advance for any help you can provide.