-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun.ino
153 lines (145 loc) · 2.9 KB
/
gun.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <Mouse.h>
#include "Keyboard.h"
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int dpi_x = 1;
int dpi_y = 1;
int dpi_mode = 2;
const int mode_1 = 1000;
const int mode_2 = 400; //with VALORANT sens 0.67
//dpi mode 1 = mouse, 2 = playing, 3 = disable
// int devide(int varible){
// return varible / 1000;
// }
// int dpi_switch(int mode){
// if (mode == 3)
// {
// mode = 1;
// }
// else
// {
// mode = mode + 1;
// }
// return mode;
// }
int dpi_set_x(int x, int mode)
{
if (mode == 1)
{
x = x / mode_1;
}
else if (mode == 2)
{
x = x / mode_2;
}
// else if (mode == 3)
// {
// x = 0;
// }
return x;
}
int dpi_set_y(int y, int mode)
{
if (mode == 1)
{
y = y / mode_1;
}
else if (mode == 2)
{
y = y / mode_2;
}
// else if (mode == 3)
// {
// y = 0;
// }
return y;
}
void setup() {
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
// Serial.begin(9600);
//Serial.print("Serial Begin");
Wire.begin();
//Serial.write("Wire begin");
mpu.initialize();
//Serial.write("MPU");
Mouse.begin();
//Serial.write("Start");
Keyboard.begin();
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
/*
Serial.print("a/g:\t");
Serial.print(devide(ax)); Serial.print("\n");
Serial.print(devide(ay)); Serial.print("\t");
Serial.print(devide(az)); Serial.print("\t");
Serial.print(devide(gx)); Serial.print("\t");
Serial.print(devide(ay)); Serial.print("\t");
Serial.println(devide(gz)); */
int bt6_Right = digitalRead(6); //Right click
int bt7_Left = digitalRead(7); //Left click
int bt8_Gun = digitalRead(8); //Gun mode
int bt4_Reload = digitalRead(4); //Reload
int bt5_Mouse = digitalRead(5); //Mouse mode
//Left click
if (bt7_Left == LOW)
{
Mouse.press(MOUSE_LEFT);
}
else
{
Mouse.release(MOUSE_LEFT);
}
//Right Click
if (bt6_Right == LOW)
{
Mouse.press(MOUSE_RIGHT);
}
else
{
Mouse.release(MOUSE_RIGHT);
}
// dpi
if (bt8_Gun == LOW)
{
if (dpi_mode == 1)
{
dpi_mode = 2;
}
Keyboard.press('1');
Keyboard.release('1');
}
if (bt5_Mouse == LOW)
{
dpi_mode = 1;
}
//Reload
if (bt4_Reload == LOW)
{
Keyboard.press('r');
Keyboard.release('r');
}
// Serial.print(gz); Serial.print("\t");
// Serial.println(gy);
dpi_x = -(dpi_set_x(gz, dpi_mode));
dpi_y = dpi_set_y(gy, dpi_mode);
Mouse.move(dpi_x, dpi_y);
// Mouse.move(-gz/1000, gy/1000);
// Serial.print("bt6_Right: ");
// Serial.println(bt6_Right);
// Serial.print("bt7_Left: ");
// Serial.println(bt7_Left);
// Serial.print("bt8_Gun: ");
// Serial.println(bt8_Gun);
// Serial.print("bt4_Reload: ");
// Serial.println(bt4_Reload);
// Serial.print("bt5_Mouse: ");
// Serial.println(bt5_Mouse);
}