
Electromechanical Game
This project was completed individually for my electronics and controls class. The goal of the project was to create a game that is fun to play, is controlled by a feather microcontroller, has a moving electromechanical element, and receives some sort of user input. I chose to create a marble game to complete these requirements.

Game Premise
For my game, I chose to make a marble path with a funnel that shakes back and forth and can be held in place by holding the blue button. To start the game, the green button is pressed, and the motor will run for 10 seconds. To win, the player must use the blue button to stop the funnel above the bottom track, so the marble can successfully complete its path.
​
To the left is a video of my friend playing the finished game. On the right is the frame that I made to hold the slides for the marble.

Building the Game
To build the physical component of my game, I designed the slides for the marble in SolidWorks. Initially, the slides were all connected, but to 3D print them as one piece would have taken too long, so this was primarily to make sure they all functioned together. I printed them individually, and left the supports on the bottom two slides to aid with assembly. I made a box out of this cool purple scrap wood I found, let the wood glue dry, and then taped my slides into place. Additionally, I taped the frame and the motor to the ground so that they would be secure while the motor ran.
Rotational to Linear Motion
To the right is a picture of my motor mechanism, and below is a video of it working. I wanted my funnel to have a horizontal motion, so I need to convert the rotational motion of the motor to linear motion. To do so, I laser cut some acrylic slots and threaded a dowel through them. There are four slots to minimize any twisting of the dowel, which was an issue prior to adding a second slot onto the motor. I also 3D printed a motor attachment that fit onto the D-shaft of the motor and extended it by half an inch to space the slots. If you look closely, there are also many acrylic washers that I added to this mechanism, that is to prevent my funnel from sliding towards or away from the motor. After making these adjustments, my dowel was constrained with 2 degrees of freedom: sliding along the horizontal slot and rotating about its axis.


Counter Balances
After making the finalizing my motor mechanism design, I added some counterweights to improve its function. Although the dowel was constrained, the weight of the funnel on one side was being countered by normal forces from the acrylic slots. Because the slots were exerting a force on the dowel, there was a significant amount of friction once the motor was turned on. To counter this, I added some bearings that fit onto my dowel, and taped them into place where the balanced the moment of the funnel.
​
Additionally, the orientation of the funnel needed to be corrected so that it would be aligned correctly for the marble. I added the largest bearing I could find to the bottom of the funnel, and tied it into place using fishing line so it could be reused. The bearing was large enough that the marble still fit through the inner diameter. When the motor is in motion, the counterweight does not prevent the funnel from spinning, but once the blue button is pressed to stop motion, the funnel will orient itself correctly.
Code and Stepper Motor Control​
​
Stepper Motor
I chose to use a stepper motor for my project because I wanted my funnel to oscillate a set distance, so being able to define a number of steps for the motor to take was helpful. Additionally I hadn't used a stepper motor before and I wanted to understand the code that controlled one.
​
Code
The code for this project was run on a Feather microcontroller. My code had two primary features: a function that stepped my motor back and forth for a set time, and a while loop that checked the state of my start button. The first function also checked the blue button; if it was pressed, the motor needed to stop.
Function: rungame(runtime)
This function ran my stepper motor 80 steps forward and back for a duration of time, runtime. After each step, the stepper motor delays for a set time, and you can change how fast the motor runs by increasing or decreasing the delay. I chose for my motor to run rather fast, with a short delay of only .003 seconds between steps.
As the stepper motor ran, I also needed my stop button to be continually checked. Rather than using a state machine to check the button, I chose to check it after each delay; because my delay was short, this was often enough for even a quick button push to be detected.

Start Button
When the feather was plugged into my game, the actual code that ran was a while loop. This loop checked to see if the green start button was pushed. If the button was pushed, it ran my function: rungame(10). The 10 sets my motor to run for ten seconds.
The while loop seen below looks more complex than it is. What it really does is detect a change in the button's state. Rather than calling my function every time it detects the button is held down, it only calls the function when the button changes state. This means that someone can press the button for just a split second, or hold it down, and the game will still run for the defined 10 seconds.
