Introduction: Improved 'Simon Says' Code
An updated 'Simple Simon' project.
Specifically, easier to work with software implementation.
Step 1: Getting Started
I started with the instructable at 'Simple-Simon-Says-Game'
Refer to it for general hardware implementation.
As I already had done a project of my own which had 4 buttons, 4 LEDs and a speaker, I used that hardware (seen above). I touched up the photos a little to change some aspects to be more appropriate for illustration in this project.
It uses an Nano 3.0 and I used different pin assignments for the peripherals.
By the way, you may also be interested in a hardware simplified version I did Instructables.com/id/Fast-Easy-Simon
Step 2: Adapting to New Hardware
The Simon_Says sketch did not work for me as the code relied on fix pin assignments. Further the code was hard to follow and had some bugs.
So I created this updated version.
- Fixed the miss use of type 'boolean' for pin numbers
- Modified the code so that it will work for any LED & button pin assignments.
- The logic flow was overly complicated and in spots too repetitive, causing it to be hard to understand and debug. So I simplified it for the most part.
- Along with other improvements like the fact that I changed the 'Tone' class object's name from 'speakerpin' to 'speaker' and created a byte variable 'speakerpin' for its pin # assignment.
- Oct 2015: allowed for fast button input sequences
A download link for my updated sketch is included here. You should find it easy to get going with your own hardware by simply changing pin assignments near the beginning of the code. Download and have fun with it.
Step 3: By Popular Demand
As there has been queries about how to use the software with a servo to operate a latch when a successful set of Simon pattern matching is done. I am including here versions of 'Simon_Says' as well as the similar 'Simon_Sings' which I adapted to be suitable for further modification with appropriate servo code. I have placed '@TODO' comments in the code of each showing where to put one's servo code.
The exact coding will be dependent on the hardware implementation and the servo library one uses. I do not have answers for servo particular issues. For that, I recommend reviewing the likes of the following:
video: How to control servos
For those needing further servo related help, I recommend a post to the servo related instructable with the most similarities to their servo implementation.