Arduino 飞鼠 空中鼠标 陀螺仪体感鼠标
### A RDUINO DIY吃鸡神器## 空中飞鼠
还在担忧你的操作不行吗?还在厌倦枯燥的操作么?想不想像实战一样,手中握着枪与人对战?
下面带你实现你的梦想。
### 硬件准备
说到增强游戏体感,拿着实体枪去战斗,第一想到的就是任天堂的zapper了,但是他的价格与游戏设定,Emm…
想要实现体感控制,作为一名爱好者,当然是DIY,首先我们需要陀螺仪来感应操控的动作 ,然后就需要一个驱动器来帮助我们处理信号并传给游戏主机,在这里我选择的开发板是Arduino Pro Micro和陀螺仪ADXL345,当然从某宝上买回来得自己焊下引脚。
### 线路图
当硬件准备好了之后就是怎么接线了
### 程序控制
下面就是程序控制了,先预装好Arduino IDE,首先要引用两个类
```
#include <mouseWheel.h>
#include <mousePress.h>
1
2
读取ADXL345的XY值
y345 = -WireRead2( ADXAddressR, DATAX0,DATAX1);
x345 = WireRead2( ADXAddressR, DATAY0,DATAY1);
if(x345<0)
x345*=1.5;
if(y345>0)
y345*=1.5;
speedoX = constrain(pow(abs(x345),2)/100,0,12700);
speedoY = constrain(pow(abs(y345),2)/100,0,12700);
speedo();
```
#### 判断上下左右
```
if( x345 > value345X ){
x = -speedoxVal;
}else if( x345 < -value345X ){
x = speedoxVal;
}else
x = 0;
if( y345 > value345Y ){
y = -speedoyPos;
}else if( y345 < -value345Y ){
y = speedoyPos;
}else
y = 0;
```
#### 左键右键连击
```
myMouseLeft.press_mouse();
myMouseRight.press_mouse();
wheel = mywheel.read_wheel();
if( millis() - clickTime > clickSpeedo ){
if(!digitalRead(CLICK))
Mouse.click();
clickTime = millis();
}
```
#### PWM控制鼠标速度
```
if( (micros() - ctrlMouseTimeX >= PWMSTOPX*80)//“停”
&& valuePWMX == true){
ctrlMouseTimeX = micros();
valuePWMX = !valuePWMX;
xVal = x;
}else if ( (micros() - ctrlMouseTimeX >= PWMGOX *80)//“走”
&& valuePWMX == false ){
ctrlMouseTimeX = micros();
valuePWMX = !valuePWMX;
xVal = 0;
}
if( (micros() - ctrlMouseTimeY >= PWMSTOPY*80) //“停”
&& valuePWMY == true){
ctrlMouseTimeY = micros();
valuePWMY = !valuePWMY;
yPos = y;
}else if ( (micros() - ctrlMouseTimeY >= PWMGOY *80)//“走”
&& valuePWMY == false ){
ctrlMouseTimeY = micros();
valuePWMY = !valuePWMY;
yPos = 0;
}
```
#### 鼠标移动
`Mouse.move( xVal ,yPos ,wheel );`
想要源码的同学点 [这里下源码](https://download.csdn.net/download/u010796249/15333368)(赚点积分)。。。。
————————————————
版权声明:本文为CSDN博主「iZaix」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u010796249/article/details/113835377
页:
[1]