This project has 3 parts: the game board/display, the controller, and the master router (Python script).Part 1 - The Display
The display is a 15x10 neopixel matrix that runs off of an Arduino Nano. It handles the game logic and input from the Python Script running off of a host computer. It displays a ball that grows and moves further down the matrix- giving an illusion of depth and the ball coming at you. If it detects that the ball is hit the ball will be redrawn going 'away' from you.
The ball's direction (either left or right) changes with each hit. If you miss the ball, the COM gets a point, but if the COM misses (a 25% chance), you get the point. This game design is similar to the Wii Sports version of tennis. The points are displayed whenever the COM scores against the player.
There is a running high-score that is stored on an I2C EEPROM, in the 0x04 address. It keeps a byte that holds the high score. If you score higher than the previous high-score, it overwrites the address. If the COM gets a score of 10, it's game over... If that is confusing, I made a logic chart:
Making the matrix will take some time, so follow the guide I made here.
The controller is another Arduino Nano that has a 9DoF stick (3v3 only!) and a HC-05 BLE module attached to it. If the acceleration of either the x or y axis is greater than a specified threshold, it sends a '1' via serial to the host PC, where it gets relayed to the display. The Nano takes a reading of the x and y accelerometer at a set interval where it then checks if the values fall above or below 1.5 grams. In order to access the I2C 9 DoF stick, you must install the Sparkfun library which can be downloaded here. There is also a tutorial on how to hook up the sensor and run basic programs with it here.
To build the racquet I used a box and then cut out a racquet shape on a piece of cardboard. From there it was easy- just put a piece of white paper over the cardboard cutout and draw a design over the paper. I used a 9v battery to power the setup, just be sure to run the battery through the Vin pin on the Nano, or else it will be an unregulated 9v! Here is a picture of the internals inside the racquet:
So now you may be wondering, what controls this complex operation? How does the racquet talk to the display? Here's a secret: they don't talk to each other! There is a simple Python script that uses the incoming Bluetooth COM port and the matrix COM port to relay information between them. It also helps to sync the two systems, as they both reset when the serial ports initialize. The racquet sends a '1' to the Python script via Bluetooth, and then the Python script sends a '1' to matrix. There is a debounce of 1 sec so the serial ports don't get their buffers overflowed (they only have 32 bit buffers).The Racket
Click through the pictures to walk through how I built the racquet:
Have fun with your new tennis game!
A video of tennis being played: