Things used in this project:
Story
One of my favorite childhood party favors were the little round ball mazes you could find in the dollar section of Target. Despite its simple concept, I would rotate the plastic disk for hours trying to get the small metal ball to the center. I decided I wanted to create a “grown-up” version of this ball maze, primarily relying on two components: an LED board and an accelerometer.
I created a base maze and converted this code which displays the maze structure in white. The “ball,” indicated by a colored LED, migrates as the LED board is tilted, simulating the metal ball rolling due to gravity. The changes in direction are detected using an accelerometer/gyroscope combination (MPU-6050) which outputs changes in linear and rotational acceleration in the x/y/z directions. The outputs from the MPU-6050 are compared to movement thresholds which determine whether the “ball” should move left, right, up, or down. Keep tilting the board in the desired direction until it hits the maze structure, then change direction to keep exploring. Your goal: move the “ball” from its starting position in the top left corner to the winning position in the bottom left!
While the maze structure is quite advanced, the overall system leaves room for future improvements. Modifications such as various maze structure levels, recording the time of completion, changing the ball’s speed in correlation to the amount of tilt applied to the board, and adding dynamic components (for example, the power pellets and ghosts within the Pac-Man games) would all make the system much more advanced (and fun!).
Current System
Given delays in part delivery for the ENGI 301 course, I moved forward with creating a proof-of-concept script that pushes a pixel through the maze using a random number generator. The script will run and output an image for each time the loop is run, showing the movement of the pixel over time.
Instructions
In order to run the code, connect your Pocketbeagle to your desktop, ensure it is connected to the network, and open the Cloud9 IDE. Open all 3 scripts included in the "code" folder. Ensure that you have the following python version 3+ installed, and run the following commands:
sudo apt-get update
sudo apt-get install build-essential python-dev python-setuptools python-smbus -y
sudo apt-get install python-pip python3-pip -y
sudo apt-get install zip
sudo pip3 install --upgrade setuptools
sudo pip3 install --upgrade Adafruit_BBIO
sudo pip3 install adafruit-blinka
In addition, install the following python libraries/functionalities for this project (import code is included in the python scripts):
Pillow (PIL)
colorsys
time
numpy
io
board
random
math
adafruit_mpu6050
Then run this command:
sudo python3 maze_game.py
Type in the sudo password, and run. A series of .tmp images will appear in the folder in which the scripts are saved, as the random number generator pushes the pixel through the maze. Click control + C to stop the algorithm, or allow it to run until the pixel reaches the finish point, in which case the script will stop running automatically. Click through the images to see the pixel's movement randomly through the maze.
Future Steps
The future intention for these scripts is to integrate into the aforementioned maze prototype. The final edits include taking input from the accelerometer, and pushing the movement outputs to the LED board each time to move the pixel.
Comments
Please log in or sign up to comment.