Cuprins:

ITTT Rolando Ritzen - Mănușă Arcade Motion Control: 5 pași
ITTT Rolando Ritzen - Mănușă Arcade Motion Control: 5 pași
Anonim
ITTT Rolando Ritzen - Mănușă Arcade Motion Control
ITTT Rolando Ritzen - Mănușă Arcade Motion Control

Een handschoen die je kan gebruiken als motion controller for on-rail shooters. De gimmick van dit proiect este tot controlul mișcării este, inclusiv includerea schieten. (Je schiet door te "finger bangen")

Pasul 1: Het Materiaal

Het materiaal dat je gaat nodig hebben is vrij simpel. 1x Arduino pro micro al Arduino Leonardo 1x giroscop MPU6050

4x kabeli

Pasul 2: De Bekabeling

De Bekabeling
De Bekabeling

Zoals je in het schema in de afbeelding ziet is de bekabeling super simpel. MPU VCC> Arduino VCCMPU ground> Arduino groundMPU SCL> Pin 3MPU SDA> Pin 2

Pasul 3: Biblioteci 1

Biblioteci 1
Biblioteci 1

Voor dit project heb je een paar custom libraries nodig van deze link:

Descărcați fișierul ZIP prin intermediul butonului „Clonați sau descărcați” din butonul rechts bovenaan.

Pasul 4: Biblioteci 2

Biblioteci 2
Biblioteci 2

Deschideți fișierul Zip și faceți clic pe harta "Arduino". În uze deze Arduino map wil je de mapjes "I2Cdev" en "MPU6050" pakken en in Arduino libraries zetten (Program Files> Arduino> libraries)

Pasul 5: De Cod

#include

#include #include #include #include

MPU6050 mpu;

int16_t ax, ay, az, gx, gy, gz;

int16_t accx, accy, accz; int vx, vy; unghi de plutire;

// cod pentru netezire inputint readIndex = 0; const int numCitiri = 20; int angleReadings [numReadings]; int total = 0; float averageAngle = 0,0;

int vechiZ = 0;

int nou Z = 0;

void setup () {Serial.begin (115200); Wire.begin (); Mouse.begin (); mpu.initialize (); if (! mpu.testConnection ()) {while (1); }

for (int thisReading = 0; thisReading <numReadings; thisReading ++) {angleReadings [thisReading] = 0; }}

bucla nulă () {

total = total - angleReadings [readIndex];

angleReadings [readIndex] = unghi; total = total + angleReadings [readIndex]; readIndex = readIndex + 1; if (readIndex> = numReadings) {readIndex = 0; }

if (gz> 30000) {Serial.println ("Bang"); Mouse.click (); // Trage aruncând arma înapoi (lovirea degetelor)}

// accx, accy, accz;

mpu.getMotion6 (& ax, & ay, & az, & gx, & gy, & gz); mpu.getAcceleration (& accx, & accy, & accz); //Serial.println(gy); // Serial.println (unghi);

vechiZ = nouZ;

vx = (gx + 1000) / 150; vy = - (gz - 200) / 150; Mouse.move (vx, vy); întârziere (20);

Dit stukje code heeft een beetje uitleg nodig omdat je het waarschijnlijk een klein beetje moet aanpassen.

Wat er waarschijnlijk gaat gebeuren is dat je cursor uit zichzelf over je screen gaat bewegen (van rechts naar links, van boven naar onder of diagonaal) en dit stukje code zorgt er voor dat je curor stil blijft staan als je geen input geeft. Je moet de values in in "gx + 1000" en "gz - 200" aanpassen totdat je het results krijgt dat je wil en ik denk dat de values die wil nodig hebt afhankelijk zijn van je screen resolutie. Als de cursor uit zichzelf van rechts naar links beweegd wil je "gx + x" aanpassen. Als de cursor uit zichzelf van boven naar onder beweegd wil je de "gz - x" aan passen. Als het diagonaal beweegd, dan kies je een van de twee values om aan te passen totdat hij nog maar over een as beweegd en dan pas je de andere aan.

Serial.print ("gx =");

Serial.print (gx); Serial.print ("| gz ="); Serial.print (gz); Serial.print ("| gy ="); Serial.println (gy); if (gx> 32000) {Serial.println ("Flick Right"); // Reîncărcați când aruncați arma spre Keyboard.write dreapta („r”); întârziere (250); } Serial.print ("accx ="); Serial.print (accx); Serial.print ("| accy ="); Serial.print (accy); Serial.print ("| accz ="); Serial.println (accz); // working // angle = atan2 ((float) (ay - 16384), (float) (ax - 16384)) * (180.0 / PI) * -1; angle = atan2 ((float) ay, (float) ~ ax) * (180.0 / PI); // float angle = atan2 ((float) ay, (float) -ax) * (180.0 / PI); //Serial.println(averageAngle); }

Recomandat: