Change BNO005 library to mpu6050

Hi guys, this Code i got from internet is a headtracker relative steer but for adafruit BNO005 on Arduino micro and i have mpu6050 on Arduino micro....

I need that if i tilt the head a little bit to right for ex It Will tilt the mouse endless till you center head on screen again

Can you help me to change libraries and code to use on mpu6050 please? Thanks!!!!!!

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>


/* Set the delay between fresh samples EXPECT HIGH REFRESH*/
#define BNO055_SAMPLERATE_DELAY_MS (10)


float horizontal_angle = 0;
float horizontal_offset = 0;


float verticle_angle = 0;
float verticle_offset = 0;


const int buttonGndPin = 6;
const int buttonPin = 7;

int buttonState = 0;
int prevButtonState = 0;

int incoming = 0;

   
Adafruit_BNO055 bno = Adafruit_BNO055(55);



void displaySensorDetails(void)
{
  sensor_t sensor;
  bno.getSensor(&sensor);
  
  
  
  
  
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");  
  Serial.println("------------------------------------");

  Serial.println("");

  Serial.println("waiting 2 seconds");
  
  delay(2000);
}

/**************************************************************************/
/*
    Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void) 
{
  Serial.begin(9600);



  

  
  Serial.println("\r\nORIENTATION SENSOR STARTED");
  delay(1000);
  /* Initialise the sensor */
  if(!bno.begin())
  {
    /* There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  delay(1000);
    
  /* Display some basic information on this sensor */
  displaySensorDetails();

  bno.setExtCrystalUse(true);



  pinMode(buttonGndPin, OUTPUT); 
  digitalWrite(buttonGndPin, LOW); 
      
  pinMode(buttonPin, INPUT);  


  delay(3000);

    

  Mouse.begin();
}



/**************************************************************************/
/*
    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
*/
/**************************************************************************/
void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event; 
  bno.getEvent(&event);



  //CONVERT OUTPUT FROM Adafruit_BNO055
  //**************************************************
  if(event.orientation.x > 180){
    horizontal_angle = (event.orientation.x -360) + horizontal_offset;
  }else{
    horizontal_angle = event.orientation.x + horizontal_offset;
  }
  
  verticle_angle = event.orientation.y + verticle_offset;
  //CONVERT OUTPUT FROM Adafruit_BNO055



  //get current button state
  buttonState = digitalRead(buttonPin);





  //DISPLAY DATA FROM Adafruit_BNO055
  //*************************************************************
  Serial.print("X: ");
  Serial.print(event.orientation.x, 4);     
  
  Serial.print("  horizontal angle: ");
  Serial.print(horizontal_angle, 4);   

    Serial.print("  horizontal offest: ");
  Serial.print(horizontal_offset, 4);   
  
  Serial.print("  Y: ");
  Serial.print(event.orientation.y, 4);

  Serial.print("  verticle angle: ");
  Serial.print(verticle_angle, 4);   

  Serial.print("  verticle offest: ");
  Serial.print(verticle_offset, 4);   
  

  Serial.print("  Z: ");
  Serial.print(event.orientation.z, 4);

  Serial.print("  button: ");
  Serial.print(buttonState);

  

  Serial.print("  millis:: ");
  Serial.print(millis()); 
  
  Serial.println("");



  //ACT ON DATA
  //************************************************************
  //if button is on then move mouse
  if(buttonState==1){
      Mouse.move((int)horizontal_angle, (int)verticle_angle, 0);
  }


  //check that the button was off but is now on (change of state)
  if(buttonState==1&&prevButtonState==0){
    Serial.println("RESET CENTER");
    if(event.orientation.x > 180){
      horizontal_offset = -(event.orientation.x -360);
    }else{
      horizontal_offset = -event.orientation.x;
    }
  
    verticle_offset = -(event.orientation.y);
  }

  //save the current button state for the next loop
  prevButtonState = buttonState;
  
  //************************************************************
  
  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Have you tried any of the 4 libraries for the mpu6050 that are available through the IDE Library Manager? Might be a good place to start if you haven't. Most will have examples to help you get started.

Yes Buddy i tried but the way to code mpu6050 on this sketch wont be the same no?
Its coz i need just that Code that is a special headtracking relative steer

This for the example:

Adafruit_BNO055 bno = Adafruit_BNO055(55);



void displaySensorDetails(void)
{
  sensor_t sensor;
  bno.getSensor(&sensor);
  
  
  
  
  
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");  
  Serial.println("------------------------------------");

Look for headtracker code using the MPU-6050.

I did but there its absolut headtracker Code this is the only i found with relative steer

Example:

The MPU-6050 alone cannot be used for absolute orientation, because it does not have a magnetometer or other yaw reference.

Don't waste your time with youtube videos, and avoid Instructables, as most of those are crap.

Re-edited!

I mean that i need relative orientation not absolute
This for ex:. Beating Tux Racer with a DIY Ardunio head-tracker Joystick based on MPU6050 - YouTube
In this video is using mpu6050 but is moving the joystick and i need move the mouse

I need that if i tilt the head a little bit to right for example it will tilt the mouse to right endless until i return the focus to the middle of the screen

Please take a few moments to post in clear, understandable English.

Ok atm i got this Code working, not perfect but working:

Transmisor

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


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



void setup() {

  Serial.begin(9600);
  Wire.begin();
  
  mpu.initialize();
}

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

long x=map(ax,-17000,17000,20000,20008);
long y=map(ay,-17000,17000,30000,30008);
Serial.println(x);
delay(10);
Serial.println(y);
delay(10);
if( analogRead(A0)>= 1000){
  Serial.println(80000);
}
if( analogRead(A1)>= 1000){
  Serial.println(90000);
}
if( analogRead(A3) >= 1000){
  Serial.println(70000);
}if( analogRead(A4)>= 1000){
  Serial.println(60000);
}
if( analogRead(A5)>= 1000){
  Serial.println(60500);
}



}

Receptor

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


SoftwareSerial mySerial(9, 8); // RX, TX
long serialA;
void setup() { // initialize the buttons' inputs:
  Serial.begin(9600);
  mySerial.begin(9600);
  Mouse.begin();
  Keyboard.begin();
}

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

  }   

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

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

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

    }  
Mouse.move(x, y);


    if (serialA== 80000){
    
    Serial.println("Left");
    Mouse.press(MOUSE_RIGHT);
    Serial.println(serialA);
    
    delay(10);

    }
    
    if (serialA== 90000){
    
    Serial.println("Right");
      Mouse.press(MOUSE_LEFT);
    Serial.println(serialA);
 
    delay(10);

    }
     if (serialA== 70000){
    
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('c');
    delay(60);
    Keyboard.releaseAll();

    }
     if (serialA== 60500){
    
      Keyboard.press(KEY_LEFT_CTRL);
      Keyboard.press(KEY_LEFT_ALT);
      Keyboard.press(KEY_DELETE);
      delay(60);
      Keyboard.releaseAll();

    }
     if (serialA== 60000){

     Keyboard.press(KEY_LEFT_CTRL);
     Keyboard.press('v');
     delay(60);
     Keyboard.releaseAll();

    }else{
              
 Mouse.release(MOUSE_LEFT);
  Mouse.release(MOUSE_RIGHT);
      
    }

}

UPDATE!!!!

Can i just make z on transmisor and read x on receptor? Coz i dont wanna tilt to left or right only rotate