Hope you can help me!
I want to controle my pc cursor with the values from an gyroscope and an accelerometer. So basically when I move the sensor, the cursor should be moved. I used an MPU-6050 chip and an ESP32.
How I get the position of the cursor:
public static void main (String[] args){
for(int i = 0; i<= 1000000; i++) {
PointerInfo info = MouseInfo.getPointerInfo();
Point location = info.getLocation();
System.out.println("x="+ location.x + " y=" + location.y);
}
How I will get the values from the sensor:
public SensorData(JsonObject data) {
//accerlation accelerometer
ax = data.get("ax").asDouble()/ASENSETIFITY;
ay = data.get("ay").asDouble()/ASENSETIFITY;
az = data.get("az").asDouble()/ASENSETIFITY;
//temperature
temp = data.get("t").asDouble()/340.00+36.53;
//gyroscope
gx = data.get("gx").asDouble()/GSENSETIFITY;
gy = data.get("gy").asDouble()/GSENSETIFITY;
gz = data.get("gz").asDouble()/GSENSETIFITY;
}
public String toString() {
return "ax: " + Double.toString(ax) +", ay: " + Double.toString(ay)
+", az: " + Double.toString(az) +", temp: " + Double.toString(temp)
+", gx: " + Double.toString(gx) +", gy: " + Double.toString(gy)
+", gz: " + Double.toString(gz);
}
What I got so far:
package mouse;
import java.awt.AWTException;
import java.awt.Robot;
import Connection.SensorData;
public class MouseMoving {
Robot robot;
public MouseMoving(){
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void verarbeite(SensorData data){
System.out.print("Deine Maus befindet sich da:");
System.out.println(data);
//robot.mouseMove(1,1);
}
}
My Question:
How can I now controle the cursor? Do you have an idea?
I thought, that you need the last position of the mouse cursor, then get the current position of the sensor and change the mouse position. But how can I write this whith my values?
I found this website, where 3 objects where rotated on the pc when the sensor will be moved. But this isn't written in Java and I don't understand his solution.
Also I found this and this question. Maybe it will work like that. But I haven't been programming that long and don't understand it.