Tic Tac Toe is a two player game in which the players compete to get 3 pieces in a row. In this project we constructed a Tic Tac Toe game using a number pad and neo pixels as pieces. This results in a portable Tic Tac Toe game requiring only a wall outlet to play.
- Neo Pixel LEDs
- Membrane switch module
- Arduino Uno
- Power Supply (Arduino) (9V 2.5A)
- Wires Prototype board
- Breadboard (for testing)
- 3D printer3D print Filament
- M2.5 crews and nuts
The attached files contains pricing and links for the materials. The list was created early in 2021 so the prices may change. The neo pixels listed were used when we made this project, we suggest using neo pixel strips to avoid having to solder each of the individual neo pixels together.
Step 1: Concept
Step 2: Circuit Diagram
Step 3: Arduino Uno Code
In state 1 the player is deciding whether blue or red will play first. If a number 1-9 is pressed then blue will play first, if A, B, C, D, or # is pressed and then 1-9 is pressed then red will play first.
State two then functions as the launchpad for the rest of the game as state 1 is only used on initialization and resets. From state two when a number is pressed the code runs through state three to check if the space corresponding to that number is taken.
In state three, if the space is taken, the code sends you to state six which plays a space taken animation. This animation flashes the color that is has already taken the space. Once the animation plays through the code sends you back to state two awaiting another input. If a number is pressed and the corresponding space is not taken, the code send you to state four.
In state four the neo pixels are lit. State four is the state that the code will switch the inputs from blue to red. Any time a neo pixel is lit, the coordinates are translated into a 2D array. The concept for the array is this, when the game initializes or resets the array is filled with zeroes. Anytime a neo pixel is lit, a number is placed into the corresponding location in the array, a 1 for red and a 2 for blue. By placing the different values in the array we are able to check for win conditions based on color. From state four the code goes to state five and checks for a win condition.
In state five, if no win is detected and there are still spaces open (zero’s present in the array), then the code goes back to state two and the loop continues. If there is no win detected and there are no spaces open (the array is filled with 1’s and 2’s with no zeroes), then the code goes to state seven and plays a tie game animation. States eight and nine is a red and blue win respectively, these states will play the win animation for the given color.
From states seven, eight, and nine, the code goes to state ten. State ten is the holding pattern where the code will wait until the game is reset using the ” * ” key.
Of note, the ” * ” key can be used at any point in the code to reset the game.
The design of the housing is such that it grants access to the serial port on the Arduino Uno. This allows for the code to be modified at will. This can include different colors for the players, different win animations, and even different rules.
Step 4: Manufacturing
Step 5: Assembly
Step 6: Finished Product
Have a mode where one player can against the computer, simplify code, player can choose different colors to play as, and condense size of physical project.
Use neo pixel strips instead of individual neo pixels to avoid a good deal of soldering. Check continuity for every connection as you solder.
Read more: Neo Pixel Tic Tac Toe (Arduino Uno)