If you watch the Big Bang Theory you have surely heard of Sheldon's version of Rock Paper Scissors. It is Rock Paper Scissors Lizard Spock and adds a nice nerdy flair to the game. I decided a few weeks back that I needed a new desk toy at work and eventually settled on recreating this version of a simple game.
Scissors cuts Paper, Paper covers Rock, Rock crushes Lizard, Lizard poisons Spock, Spock smashes Scissors, Scissors decapitates Lizard, Lizard eats Paper, Paper disproves Spock, Spock vaporizes Rock, and as it always has Rock crushes scissors.
Step 1: Choose a Microcontroller
First thing to consider is what microcontroller and you use to power your game. The code is extremely simple and barely requires any memory so most microcontrollers will easily run this from a computing power perspective. I first thought I would use an AT Tiny 85 to power this and use shift registers to control the LEDs but given the flashing patterns I wanted and the added programming complexity I went against it.
Given that I was not going to use shift registers I determined how many total digital I/Os I would need. My conceptual design contained 5 LEDs for the computer's "throw", 5 LEDs for the player's "throw", 3 LEDs for the computer's score and 3 LEDs for the player's score. I also needed one analog in to read the five buttons and one additional I/O to control a small piezo speaker. So in total that is 17 digital outs and one analog in needed.
After a brief bit of searching I settled on Adafruit's Pro-Trinket 3.3V. This has 12 dedicated I/Os and 8 analog inputs of which 6 can be designated as additional I/Os. So by using 5 of the analog inputs as digital I/Os I would have 17 I/Os and still have at least one analog input. The 3.3V version of the Pro-Trinket also worked perfect as I planned to use a small LiPo to power everything.
Step 2: Materials
Here is the list of materials used:
- 3.3V Pro-Trinket - Adafruit - http://www.adafruit.com/products/2010
- Strip board - Amazon - http://amzn.com/B00PBGKTTA
- Perf board - Amazon - http://amzn.com/B00NQ387TY
- Resistors - all from assortment kit - Amazon - http://amzn.com/B003UC4FSS
- (2) 200 ohm resistors
- (6) 330 ohm resistors
- (1) each of 10 kohm, 8.2 kohm, 5.6 kohm, 3.9 kohm, 2.2 kohm, 100 kohm
- Plywood 0.200" thick - Hardward store
- Scrap wire - most of it from a broken ethernet cable
- LEDs - All from Jameco - www.jameco.com
- (10) yellow 5mm
- (3) red 5 mm
- (3) green 5 mm
- Piezo buzzer - had one laying around from an Arduino starter kit
- Limit Switch - snap action, the more sensitive the better. I found mine at a local surplus electronics store
- LiPoly Backpack for Pro-Trinket
- LiPo battery - 100 mAh
- (5) Tactile buttons - Amazon - http://amzn.com/B008420WOA
- Wire cutters
- Wire strippers
- Hot glue & hot glue gun
- Wood glue
- Sand paper
- Soldering iron & solder
- Laser cutter
- Inkscape software (free)
Step 3: Design Thoughts
Before we go into the details of construction I want to go over a few thoughts I had when designing.
- I wanted the box to be as thin as possible while still fitting all components yet still be able to stand up on its own sturdily.
- No PCB etching or milling for me.
- Auto shut off feature when you set it down to kill all power and save battery.
- Rechargeable battery design.
- Be just the right size to hold in your hands.
Step 4: Cut Out the Box
I designed this all in Inkscape in about an hour. I used some images I found online via a Google image search and traced them in Inkscape to get the icons I wanted. I utilized www.makercase.com to help design the box and imported that into Inkscape. I wanted to make sure the holes for the buttons were on centers that were a multiple of 0.1" to make assembly of the button board easy as can be. I have attached the PDF version of my design. You should be able to take this straight to an Epilog Laser Cutter and hit print.
Design is 4" wide, 3" tall and 1.5" deep. The back is a press fit into the body for easy removal in case anything breaks.
Step 5: Glue in the LEDs
Place some hot glue around the base of each LED then fit into the holes. Be sure to line up cathodes and anodes of the LEDs in the same "columns" as it will simplify your soldering work later. See the picture above for what it should look like upon completion.
Step 6: Prepare the PCB
I cut the strip board down to size to fit in the box while still giving me the most possible PCB real estate to work with. No direct measurements here, just eyeball it! You will then need to determine where you will place the Pro-Trinket on the board and cut the strips between the pins, otherwise you will have short circuits galore. I used a cut off wheel on my dremel to burn through the entire PCB + traces in a matter of seconds.
Next, solder on the header pins to the Pro- Trinket and then the Pro-Trinket to the PCB. I elected to have the traces facing the outside of the box (single sided PCB) and have the header pins stick through as little as possible to help eliminate short circuits against the LED leads below.
Step 7: Solder the LEDs
Next you will want to solder together the cathode (-) of each LED to the other LEDs in the same column. If you glued them in right this will be simple as you can just bend them all down in a row and solder them onto each other.
Since the yellow "selection" LEDs will only turn on one at a time for any given column we can use one current limiting resistor per column. Go ahead and solder one 200 ohm resistor to each of the common cathodes you just created on the two yellow LED columns and then solder them together on their other ends (this will be the ground side).
The red and green "score" LEDs can have multiple LEDs on at time in each column so in order to keep the same brightness and current on each LED each LED will need its own current limiting resistor. We will do that in the next step. For now, solder the common anodes you just created on each of these columns to the ground side of the two 200 ohm resistors from the yellow columns.
Now each LED will need to be connected to the Pro-Trinket by its anode. Go ahead and solder on small scraps of wire to each LED anode independently. Sixteen in all. Solder the wire as close to the base of each LED as you can to we can keep this project thin and reduce short circuit potential.
Now trim off all excess LED leads.
Refer to the picture and its caption boxes if you are confused.
Step 8: Add the Current Limiting Resistors for the Score Columns and the LiPoly Backpack
Now we need to add the current limiting resistors for each of the score LEDs. You will need to cut the traces/strips to disrupt continuity then place the resistor over that break. A picture above shows the resistors soldered in place. The 6 resistors used here are 330 ohm and work great for keeping the current draw down on the red and green LEDs while still keeping them bright.
Next, add the LiPoly backpack to the PCB. I chose to attach it to the side rather than on top of the Pro-Trinket (as it was intended) in order to keep the thickness down. Just make sure you line up the strips correctly and solder the 5V pin of the backpack to the same strip as the "BUS" pin of the Pro-Trinket. G goes to G and BAT goes to BAT+.
Step 9: Finish Off the Main PCB
I do not have a picture of this intermediate step but essentially all you are doing here is soldering the individual wires from the LED anodes to the respective pins on the Pro-Trinket. Then add your piezo buzzer and connect one leg to ground and the other to the pin your designate in your code on the Pro-Trinket.
Step 10: Make the Button Board
The last real PCB work we need to do is to create the button input board. I chose to make this board separate to help with lining up the buttons on final assembly. A smaller, secondary board is easier to manuever just right than the whole project board.
If you remember from earlier when I spoke about the laser cut design you may remeber that I mentioned placing the button holes on 0.1" centers. That comes in handy now.
Cut a piece of non strip board PCB to the size and shape needed and then place the buttons in such that they line up with the holes. We will then add different value resistors in order to create a series of voltage dividers that will be read by the lone analog pin we are using. I have attached a Fritzing diagram that shows the concept since I did not get a good picture of my final wiring. You can also check out the instructable linked below if you need help conceptualizing what we are doing here.
Once done with this board, test fit it and then connect it to the main PCB with wire. Connect the ground side of the 100kohm resistor to GND on the PCB. Connect V+ of the buttons to the regulated 3.3V output of the Pro-Trinket. Connect the "button side" of the 100kohm resistor to the analog input of your choice.
Step 11: Add the Limit Switch
Now install the limit switch that will serve as our on/off switch that turns the box off when it is set down.
First go head and glue it or bolt it in place. The little T shaped/slotted piece you cut out on the laser cutter is the stand this will attach to. You may need to modify this piece in your design and I don't have a part number to give you on this limit switch. Glue the T shaped bracket into the notch on the bottom of the case, let it dry 30 minutes. Then glue or bolt the limit switch in place. Bend the level arm of the switch carefully such that it protrudes enough to activate when set on a flat surface.
Now for the electrical connection. Start by cutting the trace on the LiPoly as highlighted in the above picture. This will kill power from the battery when the circuit is broken (by means of our switch).
Now solder the COM (common) of the limit switch to one of the solder pads. Then solder the NC (normally closed) of the limit switch to the other solder pad.
With this setup when the switch is not being depressed, aka being held, the switch will be closed, completing the circuit and supplying power from the battery. When the box is set down and the limit switch is depressed it will then open the circuit, disrupting the power. Easy peasy.
Step 12: Plug It In, Load the Code and Test
You will want to plug this in and test it before completing the case around it. Load the code (attached) and test all buttons, play a few games and feel the satisfaction of a project that is almost complete. You will love the little win and loss tones the first time you hear them.
About the code:
The code is very simple and intuitive. I know there are probably many areas of it that I could have improved upon by with switch and case statements instead of all my if, and, or statements, but I frankly don't care. I think the way it is written makes it easier for a novice (like myself) pick it up and understand it the first time through.
Tones: I had a hard time getting the tone library to work so I just copy and pasted all the internals of it into the header of my code, problem solved.
Pin assignments: Yours may be different.
Random number generation: Google "random number arduino" and get ready to read a bunch of angry nerds debating each other on what is best. Arduino tutorials suggest using a free analog input to seed the random number generator but I found that this often gave the same computer selected "throw" over and over. I ultimately decided to seed the random function with millis() because the odds are that a human is never going to press the button at the same millisecond count every time they play. I have found that this indeed feels very random and the computer wins about 40 - 50% of match ups.
Analog button values: I wrote a separate bit of code in another program to read the analog values expected for button presses and used the results from that to feed my limits in this program.
Programming the Pro-Trinket:
I found this highly frustrating and that for someone that already had the Arduino IDE installed with many other libraries from other projects the Adafruit instructions were not all that clear. They do have plenty of information over on their website though. I suggest tinkering with this and testing some simple blink sketches before uploading this code. https://learn.adafruit.com/introducing-pro-trinket...
Step 13: Glue the Case Together
Simple stuff here. Use wood glue, but don't use too much. Clamp or rubber band the box in a few places. After clamping wipe away any excess glue with a damp rag. Leave the clamps for the 30 minutes or so then it is safe to handle gently. Wait 24 hrs before you put any real stress on the box. Go ahead and add your battery and plug it into a USB charger so it can charge overnight while you wait for the glue to dry.
I added a small column of wood that presses in behind the button board to hold it firmly in place. You may choose to do the same for the main PCB but I found it fit tight enough that I did not need to.
I sanded the back panel just enough that it was a tight press fit into the opening. All you have to do to remove it is press a pencil against it from the bottom charge/programming opening.
Step 14: Finished
You are all done! Set this on your desk at home or the office as a reminder just how Sheldon-like you are. Embrace your inner nerd, don't run from it.
I think the look of this turned out great. It would look equally awesome cut out of acrylic and would be amazing if someone could incorporate Sheldon's voice in for win/loss, game start, etc.
Check out some of my other Instructables! Vote for me!