這是我的第一個(gè)項(xiàng)目,ThimbleKrox,它是一個(gè)頂針,可以讓你通過(guò)食指(或任何手指)的移動(dòng)來(lái)控制鼠標(biāo)指針。
第 1 步:所需材料和工具
所需材料:
MPU-6050
用于連接 Arduino 和 PC 的電纜(微型 USB 到 USB)
跳線(連接 Arduino 和 MPU-6050)
一個(gè)松緊帶(如果你想將 Arduino 連接到你的手上)
所需工具:
安裝了 Arduino IDE 的計(jì)算機(jī)(用于啟動(dòng) Arduino 中的代碼)
烙鐵(僅當(dāng) Arduino 未預(yù)先組裝引腳連接器時(shí))
3D 打印機(jī)(如果你想讓你的頂針看起來(lái)很酷)
第 2 步:連接
將 arduino 的引腳連接到 MPU-6050 的引腳:
Arduino的引腳VCC到引腳VCC
引腳 GND 到 GND
引腳 2 到 SDA
引腳 3 到 SCL。
第 3 步:3D 打印(可選)
如果您希望您的頂針看起來(lái)不錯(cuò),并且如果您有 3D 打印機(jī),您可以打印物理頂針。
我做了兩個(gè)版本,一個(gè)是透明的,因此不需要打印支撐并且不太笨重,第二個(gè)是我嘗試用蒸汽朋克風(fēng)格做的而不讓它太笨重(它仍然比透明的更笨重一個(gè)),但是這個(gè)需要打印支持,并且只有在彩色時(shí)才能返回最好的(對(duì)于 PLA,我與蛋彩相處得很好)。兩者都需要與底部有兩個(gè)內(nèi)部突起的部分一起打印
第 4 步:組裝
使用 3D 打印頂針
要使用印刷頂針安裝所有東西,連接后,必須將 MPU-6050 插入頂針的上腔內(nèi),將電纜容納在下腔中
沒(méi)有 3D 打印的頂針
在這種情況下,組裝以更業(yè)余的方式完成,即將 MPU-6050 放置在感興趣手指的最后一個(gè)方陣并用膠帶或松緊帶將其擋住。
第 5 步:編碼和校準(zhǔn)
運(yùn)行代碼的第一件事是安裝所需的庫(kù),即Wire.h 、I2Cdev.h 、MPU6050.h和Mouse.h
完成此操作后,我建議加載 ThimbleKrox 校準(zhǔn)代碼,戴上頂針并打開(kāi)串行監(jiān)視器(Ctrl + Shift + M)。
您現(xiàn)在應(yīng)該看到如下內(nèi)容:
right | gx = 3165 gy = 469 gz = -1055 | ax = 15232 ay = 2064 az = -4496
如果正確校準(zhǔn),您希望指針移動(dòng)的方向顯示在哪里,然后是校準(zhǔn)所需的一些值。
現(xiàn)在您必須重新打開(kāi)代碼并轉(zhuǎn)到標(biāo)有“//校準(zhǔn)線”的行并更改數(shù)值,直到獲得正確的方向。(每次更改代碼中的值時(shí),都需要在 Arduino 中重新上傳)
串行監(jiān)視器:
left | gx = 3165 gy = 469 gz = -1055 | ax = 5232 ay = 2064 az = -4496
校準(zhǔn)代碼:
if (ax> = 15000) { // calibration line
right ();
}
串行監(jiān)視器標(biāo)記為“左”,但我們希望將此行標(biāo)記為“右”,因此我們需要將“15000”值更改為“5000”。這是因?yàn)椋谶@種情況下,我們必須確保檢測(cè)到的“ax”大于代碼中的值。我們知道它必須更大,因?yàn)樵诖a中有一個(gè)主要標(biāo)志,我們必須查看串行監(jiān)視器的“ax”,因?yàn)樵诖a中有“ax”。(只需更改代碼的數(shù)值)
在 Arduino 中重新加載代碼后,我們將擁有:
串行監(jiān)視器:
right | gx = 3165 gy = 469 gz = -1055 | ax = 5232 ay = 2064 az = -4496
校準(zhǔn)代碼:
if (ax> = 5000) { // calibration line
right ();
}
當(dāng)校準(zhǔn)代碼中的所有校準(zhǔn)線都已調(diào)整,因此校準(zhǔn)版本頂針起作用時(shí),必須調(diào)整主代碼的值以匹配校準(zhǔn)代碼。
校準(zhǔn)代碼:
if (ax> = 5000) { // calibration line
right ();
}
主要代碼:
if (ax> = 15000) { // calibration line
right ();
}
主代碼必須更改為:
if (ax> = 5000) { // calibration line
right ();
}
現(xiàn)在是時(shí)候上傳主代碼了
第 6 步:完成項(xiàng)目
現(xiàn)在是時(shí)候戴上你的手指控制鼠標(biāo)用它玩 PC 游戲了!
ThimbleKrox code:
//Code to control the mouse pointer through the movement of a finger
//To calibrate the device run "ThimbleKrox calibration code" and follow the tutorial found at https://www.hackster.io/projects/dd8881/
//The lines that need to be changed for calibration have "http://calibration line"
//code write by Magform
#include
#include
#include
#include
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy;
int sensibility=10; //Change this value to change the sensitivity of the device
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) { //check connection with the MPU-6050, if there is no connection stop to work
while (1);
}
}
void up(){
Mouse.move(0, -sensibility);
}
void down(){
Mouse.move(0, sensibility);
}
void left(){
Mouse.move(-sensibility, 0);
}
void right(){
Mouse.move(sensibility, 0);
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
if(ax>=15000){ //calibration line
right();
}
if(ax<=-9000){ ? ? ? ? ? ? ? ? ? ? ? ? //calibration line
left();
}
if(ay<=-8000){ ? ? ? ? ? ? ? ? ? ? ? ? ?//calibration line
up();
}
if(ay>=10000){ //calibration line
down();
}
//uncomment the following lines to set the right click with a sprint up and the left click with a sprint down (Work in progress part)
/*
if(gy>=20000){ //calibration line
Mouse.click(MOUSE_RIGHT);
delay(100);
}
if(gy<=-20000){ ? ? ? ? ? ? ? ? ? ? ? ?//calibration line
Mouse.click(MOUSE_LEFT);
delay(100);
}
*/
delay(10);
}
-
鼠標(biāo)
+關(guān)注
關(guān)注
6文章
591瀏覽量
39914 -
控制
+關(guān)注
關(guān)注
4文章
1014瀏覽量
122774 -
MPU6050
+關(guān)注
關(guān)注
39文章
307瀏覽量
71665
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論