-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouse_Gyro.ino
49 lines (37 loc) · 939 Bytes
/
Mouse_Gyro.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
double vx, vy;
int Click=0;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
while(!mpu.testConnection());
pinMode(12,OUTPUT); //Making A GND pin on D12
digitalWrite(12,LOW);
attachInterrupt(digitalPinToInterrupt(2), LeftClickDetected, RISING);
attachInterrupt(digitalPinToInterrupt(3), RightClickDetected, RISING);
}
void loop()
{
double timer=millis();
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print(gz+10); //Calibrate the constant as per your sensor
Serial.print("\t");
Serial.print(gy-210); //Calibrate the constant as per your sensor
Serial.print("\t");
Serial.println(Click);
Click=0;
while((millis()-timer)<50);
}
void LeftClickDetected()
{
Click=1;
}
void RightClickDetected()
{
Click=2;
}