|
|
Raspberry pi pico |
x 1 | |
|
|
Mpu6050 |
x 1 | |
|
|
Jumper Cables |
x 4 |
Controlling Games With you hand
I had gotten the Rapberry pi pico a few weeks ago and I was experimenting with it. On one fine day I was learning how to use Mpu6050 with Pico and circuit python and control my mouse with it. Then while just messing around, I thought why not try to control a game? I thought asphalt 8 would be ideal as it only needs five controls ( front, back, left, right and nitro).
I did all the connections and now the cable connecting pico and mpu6050 was too short. So I made the wire longer and I had an old Mi Band lying around which was not working. So I placed the mpu6050 inside the band and used it as a wearable.
Here is a video of it working:
you can till your hand left and right to steer the car. Tilt it Forward and Backward to control the direction of the car (front and back) and flick your hand towards the top for Nitro.
the video is also posted on reddit by the username : u/hriday746 : which is me
the video is also on a blog : hridaybarot.home.blog : which is also me
the video is also on instagram by the name: friday746 : which is me
and also on youtube.
for a more detailed guide with the code, visit: https://hridaybarot.home.blog/2021/03/23/controlling-asphalt-8-with-hand-gestures-using-mpu6050-and-raspberry-pi-pico/
import time
from math import atan2, degrees
import board
import busio
import adafruit_mpu6050
from adafruit_hid.keyboard import Keyboard as kbd
from adafruit_hid.keycode import Keycode
i2c = busio.I2C(board.GP15, board.GP14)
sensor = adafruit_mpu6050.MPU6050(i2c)
import usb_hid
Keyboard=kbd(usb_hid.devices)
kw=Keycode.W
ka=Keycode.A
ks=Keycode.S
kd=Keycode.D
k_nitro=Keycode.SPACE
# Given a point (x, y) return the angle of that point relative to x axis.
# Returns: angle in degrees
def vector_2_degrees(x, y,l=False):
if l:
angle = degrees(atan2(y, x))
else:
angle = degrees(atan2(y, x))
if angle < 0:
angle += 360
return angle
# Given an accelerometer sensor object return the inclination angles of X/Z and Y/Z
# Returns: tuple containing the two angles in degrees
t=""
f=""
def get_inclination(_sensor):
x, y, z = _sensor.acceleration
return vector_2_degrees(x, z,True), vector_2_degrees(y, z), int(x),int(y),int(z)
x,y,z=0,0,0
def press(key):
Keyboard.press(key)
def release(key):
Keyboard.release(key)
turn=None
ac=None
toA=None
#l=[None,None]
while True:
try:
turn, ac,x,y,z = get_inclination(sensor)
turn=int(turn)
ac=int(ac)
except:
pass
#print(turn,ac,x,y,z,sep=" : ")
if turn<50:
if t=="r":
Keyboard.release(kd) #leave r
print("left")
Keyboard.press(ka)
#l[0]=ka
t="l"
elif turn>130:
if t=="l":
Keyboard.release(ka) #leave l
print("right")
Keyboard.press(kd)
#l[0]=kd
t="r"
else:
if t=="l":
Keyboard.release(ka) #leave l
elif t=="r":
Keyboard.release(kd) #leave r
l[0]=None
if ac<50:
if f=="f":
Keyboard.release(kw) # leave f
print("brake")
Keyboard.press(ks)
#toA=ks
f="b"
elif ac>120:
if f=="b":
Keyboard.release(ks) #leave b
print("accel")
Keyboard.press(kw)
#toA=kw
f="f"
else:
if f=="f":
Keyboard.release(kw) # leave f
elif f=="b":
Keyboard.release(ks) #leave b
if z >=11:
print("nitro")
Keyboard.send(k_nitro)
time.sleep(0.000001)
Controlling Games With you hand
Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW- Comments(0)
- Likes(1)
-
MXKA03
Apr 21,2021
- 1 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-
9design
-
9usability
-
10creativity
-
10content
More by Hriday Barot
-
ARPS-2 – Arduino-Compatible Robot Project Shield for Arduino UNO
369 0 0 -
A Compact Charging Breakout Board For Waveshare ESP32-C3
719 3 6 -
AI-driven LoRa & LLM-enabled Kiosk & Food Delivery System
696 2 0 -
-
-
-
ESP32-C3 BLE Keyboard - Battery Powered with USB-C Charging
915 0 1 -
-
mammoth-3D SLM Voron Toolhead – Manual Drill & Tap Edition
779 0 1 -
-
AEL-2011 Power Supply Module
1527 0 2







