picSimon - Handheld Microcontroller Game
in
In my recent twiddlings with Microcontrollers a project has emerged. picSimon! A re-implementation of the classic toy using a single chip, a few discrete components, a few switches, and 4 LEDs. So far it is quite a hit at home and the office. Shawn (my 6 year-old son) has gotten up to about 6 moves, I have gotten 18 (once) and at the office 12-15 seems to be the range.
Why Simon?
I had tried to think of a simple toy or game to implement as a first project with the Microchip PIC. Having had mixed results with trying to make a Propeller Clock with the Parallax Basic Stamp, I wanted something that was sure to succeed. So along in my mind came the simple Simon game.
Simon is rather simple, it has 4 buttons and 4 lights of different colors (the button and lights match color). The game blinks a random light and you must respond by pressing the corresponding button. Then the game blinks the same light and another random one, you must in turn press the corresponding buttons. And so on. With each light and button press there is an audible tone, different for each color, to give audible clues to the pattern. As time goes on it becomes quite a challenge to your memory to recall the ever increasing pattern. You get only a few seconds between each button press and are taunted with a buzzer if you miss the mark.
Design and References
To implement in the PIC Micro I started completely backwards. Designing the hardware first. This was done to ensure the hardware would satisfy the requirements. The game needs (at least) 5 outputs for LEDs and a buzzer or speaker and 4 inputs for the game buttons. So overall there needs to be 9 IO pins, ruling out the 8-pin PIC Micro chips. the PIC 16F84 is rather popular, and a few were on hand, so it was easily the choice to make. It has 18 pins and enough IO pins to satisfy the requirements. Timing is not critical so the 4MHz version would be quite adequate for all but the most demanding players :-)
A quick scan of the ‘net, specifically the PICList revealed I was not alone, others had developed PIC-based simon games. Imagine that. Thus credit must be given to those that I used in creating my version. Specifically Andrew D. Vassallo’s Simon game. His initial hardware design nearly mirrored mine with only a few pin changes. He also includes a reset and difficulty switch that were not in my design. The more variations the merrier. Most importantly however, his code is available! This was a boon to my success. I have used quite a large portion of his code, only making minor modifications for some of my own features. I’ll document these in a future posting as there are still more to be added, and commented.
Construction, Schematic, and Parts List<
The circuit is actually quite simple, as the schematic here shows. You should note how easy it would be to make this same circuit into, say, a BopIt! game, or similar. I have not used all the I/O pins, so some could be used for advanced functions, like speed, reset, replay, score, etc.
Click image for larger version.
Power is from a 9V battery connected to JP1.
It is regulated to 5V by the LM7805, quite overkill for this project.
Also, the capacitor, C2
is probably overkill as well as the
original source is DC (I might be wrong). The hardest part is fitting
all the 10k resistors for the switches and LEDs on the board. The
oscillator is a simple R-C
circuit on the OSC1
pin of the pic16F84. Timing is not critical so the component count and
cost are held to a minimum. I left MCLR
hanging, a
push-button could be put here for a soft reset. I just power-cycle
S5
to reset.
Pulling all this together was quite easy. A few items did need to be purchased at the local Radio Shack. Actually I bought them out of a few items along the way. They are not quite the component source they once were, sadly. If someone from the shack reads this, please go back to the old ways! Drop cellphones from your stores, sell more resistors!
Conclusion
Overall picSimon was an excellent project for the PIC microcontroller. There are very few components involved, so even the newest people to hardware could build it. Most of the work really goes into the code, which is where I do a much better job at things. Drop me a note and let me know what you think. I had a great time playing with the PIC microcontroller.