Evan Rust
Published © GPL3+

Minecraft Sword for Real Life

Use an actual Minecraft sword to control the character onscreen. When you swing the sword the sword onscreen also swings.

IntermediateFull instructions provided3 hours1,219
Minecraft Sword for Real Life

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1
SparkFun 9DoF Sensor Stick
SparkFun 9DoF Sensor Stick
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion 360
Autodesk Fusion 360

Hand tools and fabrication machines

CNC Router

Story

Read more

Schematics

Schematic

Code

ESP8266 Code

C/C++
#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>

LSM9DS1 imu;
#define LSM9DS1_M  0x1E 
#define LSM9DS1_AG  0x6B

#define PRINT_SPEED 500

void setup() {
  // put your setup code here, to run once:
  Wire.begin(4,5);
  Serial.begin(115200);
  imu.settings.device.commInterface = IMU_MODE_I2C;
  imu.settings.device.mAddress = LSM9DS1_M;
  imu.settings.device.agAddress = LSM9DS1_AG;
  if (!imu.begin())
  {
    Serial.println("Failed to communicate with LSM9DS1.");
    Serial.println("Double-check wiring.");
    Serial.println("Default settings in this sketch will " \
                  "work for an out of the box LSM9DS1 " \
                  "Breakout, but may need to be modified " \
                  "if the board jumpers are.");
    while (1)
      ;
  }
}

void loop() {
  // put your main code here, to run repeatedly:
if ( imu.accelAvailable() )
  {
    // To read from the accelerometer, first call the
    // readAccel() function. When it exits, it'll update the
    // ax, ay, and az variables with the most current data.
    imu.readAccel();
  }
  if(abs(imu.calcAccel(imu.ax))>1.9 || abs(imu.calcAccel(imu.ay))>1.9 || abs(imu.calcAccel(imu.az)) > 1.9){
      Serial.println("hit");
      delay(PRINT_SPEED);
    }
}

Python Code

Python
import pyautogui
from time import sleep
from serial import Serial

pa = pyautogui

ser = Serial("COM10", baudrate=115200)

x, y = pa.size()

sleep(3)

pa.moveTo(x/2,y/2)

sleep(3)

try:
    while 1:
        if ser.in_waiting:
            data = ser.readline()
            print(data)
            if data:
                pa.click()

except KeyboardInterrupt:
    ser.close()

Credits

Evan Rust

Evan Rust

120 projects • 1053 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments