Skip to content

Lilypads/IIR_application

Repository files navigation

Alt text Alt text

IIR_application

Using accelerometer sensor and Arduino to control a game.

Have a look at our video explaining what we did and filtering results: https://youtu.be/T_xc3NxIb94

Prerequisite

  1. Python

Check the following webpage for instructions on how to install latest version of python: https://www.python.org/downloads/

  1. pyFirmata2

Check the following webpage for instructions on how to install pyFirmata2: https://pypi.org/project/pyFirmata2/

  1. pynput (Keyboard Controller Library)

On a terminal, install pynput with pip or pip3.

pip install pynput

or

pip3 install pynput

Reference resource: https://pypi.org/project/pynput/

  1. Arduino board and accelerometer wired as in the circuit_diagram image above

You might need to change PORT number in the realtime_iir_main.py script to the corresponding Arduino port on your PC.

How to run the game controller

  1. Change Directory to a clone of this project in your local file system.
cd IIR_application
  1. Run the realtime_iir_main.py on the terminal.
python realtime_iir_main.py

or

python3 realtime_iir_main.py

There should be 2 plots showing up. One is the unfiltered data. The other one is the filtered data. Keep this terminal running when you play.

How to open the Demo Dinosaur game in browser

  1. Use terminal to access the game directory(webGL format file).
cd IIR_application/Dinosaur_trial1
  1. Use terminal to run http server at port 8000. Keep the terminal open (Exit shortcut: ctrl+c).
python -m http.server --cgi 8000

or

python3 -m http.server --cgi 8000
  1. On a web browser, run localhost port 8000.
http://localhost:8000/

or

http://0.0.0.0:8000/

For this demo game, shake accelerometer in z-axis to jump. Try to avoid the spikes.

Notes

You can use this controller on any other custom/pre-existing games. However, please make sure the key pressed in the controller(realtime_iir_main.py) is correspond to the game you want to play.

About

Using sensor to control a game.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published