Whack-a-Mole with PIC Microcontroller
This game is a final class project for ME430 Mechatronics. Our task was to build a device with input, output, a sensor, physical motion, and logic controlled by a microcontroller. My partner and I remade a classic game with a twist - "Whack-a-Mole, but it plays defense" was born. Our goal was to make the game impossible, or at least very hard to win. An accelerometer in the hammer detects when the player swings, signaling the game to hide the mole before the player can hit it. This project outcome was excellent: we earned an A and many compliments, and had a lot of fun making and playing it along the way. Our instructor, who taught ME430 for nearly a decade, claimed "this is the first successful Whack-a-Mole game I have ever seen" because other attempts fell short of being playable. The final version can be seen below: three moles pop out of their holes, the instrumented foam hammer cannot cause any damage, and the display gives the player feedback on timing and their current score.
Every aspect of the game was wired, coded, and physically constructed by my partner and I. Visible without the lid, the moles are mounted to servo motors on flexible plastic to endure shocks from being hit. The moles and green servo mounts were designed and 3D printed by myself. Switches (repurposed from a CNC drawing machine project) on the mole's head detect hits. The PIC is invisible underneath the wiring under the display panel. We pushed the microcontroller to it's limits with the amount of IO in the project.
Unfortunately we did not meet our goal of making the game difficult because the servos could not move the moles fast enough to avoid a hammer swing, even though the sensor detected impending hits early and reliably. Even without effective defense, the game is still fun to play.
Unfortunately we did not meet our goal of making the game difficult because the servos could not move the moles fast enough to avoid a hammer swing, even though the sensor detected impending hits early and reliably. Even without effective defense, the game is still fun to play.
Details about programming and using the PIC:
Code is written in C. We used several timer interrupts for game timing, button interrupts for detecting hits, and 3 channel analog to digital conversion to read acceleration values. We also implemented a randomized but non-repeating mole appearance sequence so the player couldn't predict the next move.
Code is written in C. We used several timer interrupts for game timing, button interrupts for detecting hits, and 3 channel analog to digital conversion to read acceleration values. We also implemented a randomized but non-repeating mole appearance sequence so the player couldn't predict the next move.
Inputs
◦3x switches detect mole hits ◦3 axis accelerometer detects when the player swings the hammer ◦Reset button restarts game |
Outputs
◦3x servos move the moles, on bendy plastic to protect servos ◦3x timer LEDs indicate time remaining. ◦Ex: When timer LED for 15 seconds goes off, > 15 seconds remain ◦When > 5 seconds remain, the 5 second timer LED will flash until time runs out ◦7-segment display: indicates score ◦Win LED: flashes when you win (by scoring 10 points within 30 seconds) ◦Lose LED: flashes if you don’t score 10 points within 30 seconds |