# Circuit Playground Minecraft Gesture Controller

## Overview

https://www.youtube.com/watch?v=VqyFZSoUBLU

Move your body to play Minecraft! What!! Yes. Check the video for a demo :)

This tutorial will show you how to make your very own gesture game controller for Minecraft (or your other fav. computer game). Move your hand(s) to walk/run/jump, look around, and attack\* all the things!

Let's get started! Grab yourself a&nbsp;[Circuit Playground Express](https://www.adafruit.com/product/3333),&nbsp;[snag my program code](https://github.com/jenfoxbot/MinecraftGestureController/tree/master), and get shakin' to play Minecraft in (srsly) the most fun way ever! :D

- **Read time** : 20 min
- **Build Time** : ~ 2 hours
- **Cost** : ~$30

_\*It is a biiiiit tricky to attack moving things (like monsters), so be careful in survival mode! Or use this to challenge your skills :)_

![](https://cdn-learn.adafruit.com/assets/assets/000/051/140/medium800/gaming_GestureController-Cover2.jpg?1518942204)

# Circuit Playground Minecraft Gesture Controller

## Helpful Background Info

To keep things short as possible, set up your Circuit Playground Express to program it in CircuitPython, add libraries, and use the Serial Monitor.&nbsp;

If you're like "what are those words", here are some tutorials to get ya started!&nbsp;

1. [Setting up the Circuit Playground Express](../../../../adafruit-circuit-playground-express/circuitpython-quickstart)
2. [Installing (all the) libraries for CPX](../../../../adafruit-circuit-playground-express/circuitpython-libraries)
3. [Using the Serial Monitor](../../../../adafruit-circuit-playground-express/connecting-to-the-serial-console)
4. [More info on CircuitPython!](../../../../welcome-to-circuitpython/what-is-circuitpython)

![](https://cdn-learn.adafruit.com/assets/assets/000/051/152/medium800/gaming_ConductiveThread.jpg?1518945653)

# Circuit Playground Minecraft Gesture Controller

## Materials

### Materials

- [Circuit Playground Express](https://www.adafruit.com/product/3333)&nbsp;(FYI: gonna call this the "CPX" to save typing)
- [MicroUSB to USB cable](https://www.adafruit.com/product/592)
- **Glove&nbsp;** -- use a thick glove or one with multiple layers (to avoid shorting the conductive thread)

- [Conductive Fabric](https://www.adafruit.com/product/1168)&nbsp;(~ 6 in. x 6 in.)
- [Conductive Thread](https://www.adafruit.com/product/640)&nbsp;(~ 24 in.)
- Regular Thread&nbsp;(~ 24 in.)
- Velcro Strips&nbsp;(two 1 in. x 1 in.)

### Tools

- Sewing Needle
- Scissors

![](https://cdn-learn.adafruit.com/assets/assets/000/051/139/medium800/gaming_Materials.jpg?1518942169)

# Circuit Playground Minecraft Gesture Controller

## Build the Glove Controller!  (Pt. 1)

_You can make the gesture controller without the glove, but the glove controller makes it easier to play, keeps the CPX in the same orientation (very important), and means you can use your fingers as added controls!_

**1. Cut rectangles of conductive fabric for the finger pads (~ 0.5 in. x 1 in.).**

**2. Use&nbsp;<u>regular thread</u>&nbsp;to sew the conductive fabric pads onto each of the glove fingers.**

Suggested to use a highlighter or other pen to avoid sewing the two sides of the glove together (learn from my mistakes bbies).

**3. Attach CPX to the glove with velcro squares.**

![](https://cdn-learn.adafruit.com/assets/assets/000/051/141/medium800/gaming_GloveController-Finished.jpg?1518942329)

![](https://cdn-learn.adafruit.com/assets/assets/000/051/142/medium800/gaming_Glove-HighlighterTechnique_In.jpg?1518942404)

![](https://cdn-learn.adafruit.com/assets/assets/000/051/143/medium800/gaming_Glove-SewingPad_CloseUP.jpg?1518942434)

# Circuit Playground Minecraft Gesture Controller

## Build the Glove Controller!  (Pt. 2)

Use an alligator clip or insulated wire to connect the CPX ground ("GND") to the thumb pad.

![gaming_GloveController-GND.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/160/medium640/gaming_GloveController-GND.jpg?1519017644)

Stitch conductive thread from the CPX capacitive touch pads (A1, A2, A3 & A4) to each of the four fingers.

Stitch conductive thread from the CPX capacitive touch pads ( **A1** , **A2** , **A3** & **A4** ) to each of the four fingers.

![gaming_ConductiveThread.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/161/medium640/gaming_ConductiveThread.jpg?1519017684)

![gaming_ConductiveThread-Closeup.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/162/medium640/gaming_ConductiveThread-Closeup.jpg?1519017694)

If you have a multimeter, check continuity between the CPX pins and the conductive thread pads.

# Circuit Playground Minecraft Gesture Controller

## Plan out your Controller!

First! What do we need to do to control Minecraft (or another awesome game)?

_This is a super helpful & fun lesson in Design Thinking, but you can skip this if you want to just use my controls. You can always come back here later if you want to make changes later :D_

# Determine (crucial) game controls.

_Note: Start simple! Figure out the most important controls for the game and start there. You can always add more later._

Here are the controls that I wanted to use while playing Minecraft.. in creative mode :) (you can use the same ones or customize your own controller!):

## Movement:

- Walk forward: **W key**
- Run: **Ctrl + W**
- Jump: **Space bar**
- Look Left & Right: **Mouse rotate**
- Walk backward: **S key**

## Actions:

- Attack: **Mouse Left Click**
- Place Block/Push/Open: **Mouse Right Click**
- Inventory: **E key**
- Escape: **ESC key**

# Decide how you want to use gestures and/or the finger pads to trigger these controls. Recommended to sketch out your plan.

## &nbsp;

## Here is my design thought process:

> _I've always wanted to feel like I was actually \*in\* a game, so I went the "cheap VR" route and used gestures to control basic movements. For walking, I went the "let's move my arms like I'm walking" route, which easily transitioned into running and jumping by increasing the speed of motion._
> 
> _To make it easy to place a block or exchange items, I decided to use an "awkward handshake" motion._
> 
> _Turning was a bit of a challenge, but my goal was to be able to look around by moving my hands in the direction I wanted to look._
> 
> _Attack became the pointer finger pad, inventory the middle finger pad (which I ended up removing), Escape the ring finger pad, and the pinky finger pad to let me to walk backwards._

Again, you can keep these same controls or design your own :D

![](https://cdn-learn.adafruit.com/assets/assets/000/051/147/medium800/gaming_ControllerDesign.jpg?1518944283)

# Circuit Playground Minecraft Gesture Controller

## Program the Circuit Playground Express!

![](https://cdn-learn.adafruit.com/assets/assets/000/051/148/medium800/gaming_ProgramCPX.jpg?1518944535)

Warning: 

The CPX has an on-board compiler, which means you can program it in (pretty much) any language you want! I opted for CircuitPython, a version of Python for microcontrollers, 'cause Python is awesome.

[Here's the GitHub repository](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/Minecraft_Gesture_Controller)&nbsp;that has the full code. The same code is embeded below, simply click the&nbsp; **Download** link to save as **code.py** on your CIRCUITPY drive on the CPX

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Minecraft_Gesture_Controller/code.py

Info: 

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/Minecraft_Gesture_Controller.png)

# Required Libraries

To do the things we want with our controller, we need the following CircuitPython libraries. All are available in the bundle, [you can learn how to install it here](../../../../adafruit-circuit-playground-express/circuitpython-libraries).

- **LIS3DH accelerometer**  

  - This allows us to use motion to trigger various things.

- **Human Interface Device ("HID") keyboard**  

  - This library allows us to control the keyboard!

- **HID mouse**  

  - This library means we can control the mouse!

- **CPX capacitive touch**
  - This library lets us use the capacitive touch feature on the CPX, hooray!

- A couple of other built-in libraries to make our lives easier: **time** , **usb\_hid** , **busio** , and&nbsp; **board**.

```python
##########################
##        Libraries     ##
##########################
import touchio
import board
import busio
import time
import usb_hid
#Libraries for HID Keyboard &amp; Mouse
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.mouse import Mouse
#Libraries for accelerometer
import adafruit_lis3dh
```

# Configure and initialize the libraries

Assign variables for the keyboard, mouse, and accelerometer objects. Select a range for the accelerometer.

```python
#######################
#     CPX Setup       #
#######################
touch_a1 = touchio.TouchIn(board.A1)
touch_a1.threshold = 2000
touch_a2 = touchio.TouchIn(board.A2)
touch_a2.threshold = 2000
touch_a3 = touchio.TouchIn(board.A3)
touch_a3.threshold = 2000
touch_a4 = touchio.TouchIn(board.A4)
touch_a4.threshold = 2000
 
############################
# Keyboard &amp; Mouse Setup   #
############################
# The keyboard object!
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)
#The mouse object! 
mouse = Mouse(usb_hid.devices)
 
#######################
# Accelerometer Setup #
#######################
#Initialize Accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=25)
# Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G).
lis3dh.range = adafruit_lis3dh.RANGE_8_G
```

# Write short functions for each of the controls

The motion controls can be tricky. We did some initial testing with the accelerometer by printing the values in a serial monitor (in the source code, go to the 'main loop' `while True:` section and uncomment the two debugging lines). This will help you to determine thresholds for walking, running and jumping, looking left and right, and placing objects.

The touch pad triggers are much easier as you are only looking for a capacitive trigger (`True`/`False`) when you read the `touch_an.value`

**Remember to release all of the keyboard and mouse keys at the end of each function!** Otherwise you'll end up with stuck keys, in which case you can always unplug the USB cable

# Circuit Playground Minecraft Gesture Controller

## Test & Adjust

Don't forget you have to load the program onto the CPX by dragging and dropping the python file onto the **CIRCUITPY** drive, then rename the file as `code.py` or `main.py` (and back up your previous program first)

Like pretty much every project, this one will likely be a little wonky when you first get it running. If the touch pads are acting strange, reset the CPX (this recalibrates the capacitive input pins) by clicking the **RESET** mini button

# Test #1

1. [Open up the serial monitor with Mu](../../../../adafruit-circuit-playground-express/connecting-to-the-serial-console) (or PuTTY or any other serial monitor) and run the program (CTRL + D)
2. Test each of the movement controls (you’ll see the mouse moving on the screen and make sure the program doesn’t crash as well as the touch pads (which should display relevant text on the serial monitor).

![](https://cdn-learn.adafruit.com/assets/assets/000/051/159/medium800/gaming_CPX_Program-SerialPortTesting.jpg?1519014770)

# Test #2

Deploy in Minecraft creative mode! Test the movement and action controls to see if anything breaks or doesn’t work as expected (plz keep in mind that this is a prototype!)

Update the program based on your testing. Remember, it’s OK if it’s not perfect, there’s always time to make it better! :)

# Circuit Playground Minecraft Gesture Controller

## Run Wild!

You’re ready to run through Minecraft!! Just be wary of monsters, it might be a bit tricky to protect yourself.. dun dun dunnnnn!!

Supplementing your gesture controller with a keyboard is a good idea if you want play for reals.

Please like and/or leave a comment if you enjoyed the tutorial! And of course, let me know if you have any comments or questions!  
Happy Building!

\<3, jenfoxbot

![](https://cdn-learn.adafruit.com/assets/assets/000/051/151/medium800/gaming_GestureController-Cover6.jpg?1518944936)


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### Circuit Playground Express - Base Kit

[Circuit Playground Express - Base Kit](https://www.adafruit.com/product/3517)
It's the **Circuit Playground Express Base Kit!** &nbsp;It provides&nbsp;the few things you'll need to get started with the new [Circuit Playground Express](https://www.adafruit.com/product/3333).&nbsp;This version of Circuit Playground is super powered, and will...

In Stock
[Buy Now](https://www.adafruit.com/product/3517)
[Related Guides to the Product](https://learn.adafruit.com/products/3517/guides)
### Circuit Playground Express Advanced Pack

[Circuit Playground Express Advanced Pack](https://www.adafruit.com/product/2769)
 **Circuit Playground Express** &nbsp;is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to program....

In Stock
[Buy Now](https://www.adafruit.com/product/2769)
[Related Guides to the Product](https://learn.adafruit.com/products/2769/guides)
### Woven Conductive Fabric - 20cm square

[Woven Conductive Fabric - 20cm square](https://www.adafruit.com/product/1168)
This woven conductive fabric is silver colored and made of Copper+Nickel-plated polyester. Use small pieces for soft switches, plush keypads, capacitive touch sensors, and other textile interfaces. This highly conductive fabric has a resistance of less than 1 ohm per foot in any direction...

In Stock
[Buy Now](https://www.adafruit.com/product/1168)
[Related Guides to the Product](https://learn.adafruit.com/products/1168/guides)
### Stainless Thin Conductive Thread - 2 ply - 23 meter/76 ft

[Stainless Thin Conductive Thread - 2 ply - 23 meter/76 ft](https://www.adafruit.com/product/640)
After months of searching, we finally have what we consider to be the ultimate conductive thread. It's thin, strong, smooth, and made completely of 316L stainless steel. Once you start working with this thread you'll quickly agree its optimal for any wearables work!  
  
This...

In Stock
[Buy Now](https://www.adafruit.com/product/640)
[Related Guides to the Product](https://learn.adafruit.com/products/640/guides)
### Needle set - 3/9 sizes - 20 needles

[Needle set - 3/9 sizes - 20 needles](https://www.adafruit.com/product/615)
Mighty needles, sew like the wind! This needle set is the only one you'll need for any sort of hand sewing, especially using our conductive thread and wearable electronics parts.  
  
Each pack contains 20 gold-eye sharps, with eye sizes ranging from #3 (1.75" long) to #9...

In Stock
[Buy Now](https://www.adafruit.com/product/615)
[Related Guides to the Product](https://learn.adafruit.com/products/615/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Circuit Playground Express Perk-up Ears](https://learn.adafruit.com/perk-up-ears.md)
- [SpaceX Helmet](https://learn.adafruit.com/spacex-helmet.md)
- [Buttermilk Boat with Circuit Playground Express](https://learn.adafruit.com/boat-with-circuit-playground-express.md)
- [Comparison and Experimentation with Flammable Gas Sensors](https://learn.adafruit.com/gas-sensor-comparison.md)
- [Using DS18B20 Temperature Sensor with CircuitPython](https://learn.adafruit.com/using-ds18b20-temperature-sensor-with-circuitpython.md)
- [Crickit Powered Dancin' Snowman!](https://learn.adafruit.com/crickit-powered-dancin-snowman.md)
- [Circuit Playground Hourglass](https://learn.adafruit.com/circuit-playground-hourglass.md)
- [Make It a Keyboard](https://learn.adafruit.com/make-it-a-keyboard.md)
- [LED Breath Stats Mask](https://learn.adafruit.com/led-breath-stats-mask.md)
- [Make It Glow - Your First NeoPixel Project](https://learn.adafruit.com/make-it-glow-your-first-neopixel-project.md)
- [Wind Blowing Emoji Prop](https://learn.adafruit.com/wind-face-emoji.md)
- [CircuitPython Hardware: ILI9341 TFT & FeatherWing](https://learn.adafruit.com/micropython-hardware-ili9341-tft-and-featherwing.md)
- [Circuit Playground Express Rocket Lamp](https://learn.adafruit.com/cpx-rocket-lamp.md)
- [Adafruit Circuit Playground TFT Gizmo](https://learn.adafruit.com/adafruit-tft-gizmo.md)
