Accelerometer mouse change tilt right or left for a move lateral, pich and yaw

RE-Edited!

Hello! i have a code working for accelerometer air mouse with transmisor and receptor with tilt X and Y tilting up or down its okei but i want to change y for z coz i dont wanna tilt on Y only rotate with z, basicly i need to use pitch and yaw not roll

i try to do this:

Any help?
Thank you!! :smiley:

maybe i need to implement some gyro code?

Receptor

long x;
long y;

#include "Keyboard.h"
#include "Mouse.h"
#include <SoftwareSerial.h>
// software serial//Software Serial Port


SoftwareSerial HC05_Serial(9, 10); // RX, TX
long serialA;
void setup() { // initialize the buttons' inputs:
  Serial.begin(38400);
  HC05_Serial.begin(38400);
  Mouse.begin();
  Keyboard.begin();

  delay(1000);
  Serial.println("Initialization Done!");
}

void loop() {
         
       if (HC05_Serial.available() > 2) {
  serialA = HC05_Serial.parseInt();
  Serial.println(serialA);

  }   


    if (serialA>= 19997 && serialA <20008){
    

    Serial.println("xread");
    Serial.println(x);
    
x=map(serialA,19997,20008,-4,4);
    delay(10);

    }
    
    if (serialA>= 29997 && serialA <30008){
    
    Serial.println("yread");
   Serial.println(y);
   y=map(serialA,29997,30008,-4,4);
   
    delay(10);

    }  
Mouse.move(x, y);

      

}

Transmisor

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>


MPU6050 mpu;
int16_t ax, ay, az; 
int16_t gx, gy, gz; 



void setup() {

  Serial2.begin(38400);
  Wire.begin();
  
  mpu.initialize();
}

void loop() {
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

long x=map(ax,-17000,17000,19997,20008);
long y=map(ay,-17000,17000,29997,30008);

Serial2.println(x);
delay(10);
Serial2.println(y);
delay(10);



}

The MPU6050 has a Digital Motion Processor (DMP) that runs sensor fusion and complementary filters. It's much better than just reading the raw values.

Pieter

Is there any way to implement z on my Code please?? I need rotate Z to move cursor to sides un horizontal... Thanks really!

Can i just add a endless movement to the side i move with a normal gyro code?

Or just use the accelerometer but only with pitch and yaw?