I am using a MPU6050 to work as a wireless bluetooth mouse. I have successfully paired and configured my RN-42 in HID Mouse mode but I am unable to make it move. Can anyone please tell if this code is alright.
s#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#define LBUT 4
#define RBUT 5
MPU6050 mpu;
uint8_t buffer[7];
int16_t ax, ay, az, gx, gy, gz;
void setup() {
Serial.begin(9600);
pinMode(LBUT, INPUT);
digitalWrite(LBUT, HIGH);
pinMode(RBUT, INPUT);
digitalWrite(RBUT, HIGH);
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) {
while (1);
}
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int vx = map(ax, -16000, 16000, 90, -90);
int vy = map(ay, -16000, 16000, 90, -90);
Serial.print("vx = ");
Serial.print(vx);
Serial.print("\t vy = ");
Serial.println(vy);
if (LBUT == HIGH){
buffer[3] = 0x01; //left mouse button press
}
else (RBUT == HIGH){
buffer[3] = 0x02 //right mouse button
}
buffer[4] = byte( vx );
buffer[5] = byte( vy );
buffer[0] = 0xFD;
buffer[1] = 0x05;
buffer[2] = 0x02;
buffer[6] = 0x00;
Serial.write( buffer, 7 );
Serial.flush();
delay(17); // little delay for next reading.