Just like cell phones, computers, smart watches and wearables “Simon Says” consists of two major systems one clearly visible – the Hardware – and the other – the Software – hidden from sight. For this discussion, we’re focusing on SparkFun’s Simon Says Through Hole Soldering Kit!
Computing systems often interact with other systems – think cars, satellites, even phones. The interaction happens through the hardware system. The hardware system enables interactions with the physical world, taking inputs from the world and providing output to the world. In todays computing systems, the hardware system is generally responsible for translating information to and from the world to the brains of the hardware system – a processor. For the “Simon Says” the processing brains happens to be a microprocessor. The microprocessor is where the second major system – the Software – is hiding.
The software subsystem is responsible for taking signals (translated, filtered and sanitized by the hardware system) and performing logical operations on these signals. The software system is the “brains” – it performs all of the calculations and maintains the logical state of the system. The processor itself is also a hardware system! Just like our brains are made of cells, the wiring of those cells allows us to think, process and control our bodies .
Maybe a picture will help? Sure it’s an over-simplification – so if you ever find yourself on this spectrum (or you’re reading this and already are on the spectrum) you’ll likely feel that in reality, the spectrum isn’t so crisply defined. The major take away is the following:
Looking at the Simon Says system, what are the inputs and output to the system?
With those input and outputs defined, can you describe the logic within the Simon Says system?
After you go through this thought exercise check out the following, simplified python code which emulates the logic of Simon Says at a very high level. Afterwards, compare it to your original thoughts – think you can modify the code? There’s a link for you to try!
rounds = 5
colors = ["Red","Blue","Yellow","Green"]
simonsColors = 
for x in range(0,rounds):
colorIndex = random.randint(0, 3)
colorToAdd = colors[colorIndex]
print "Simon Says New color is ", colorToAdd
correctColors = 0
for currColor in simonsColors:
questionString = 'Enter color # '+str(correctColors+1)+':'
guessColor = raw_input(questionString)
if guessColor == currColor:
correctColors = correctColors+1
if not correctColors == len(simonsColors):
if len(simonsColors) == rounds:
print "You Won with this sequence:\n" , simonsColors
print "Sorry you lose"
Okay – so now let’s look at the real code!
The code running on the SparkFun Simon Says can be found for free on GitHub. While there are many files, the one that contains the portion of interest is here! The code uses an idea called abstraction, in which code is broken down into small manageable functions. Here’s the top level Simon Says code for a single player game, it makes assumptions about a value that should have previously been defined ( ROUNDS_TO_WIN , gameBoard), as well as a few other functions which modify gameBoard : add_to_moves() , playMoves(). When you begin investigating the code, you will notice even more functions within these functions.
randomSeed(millis()); // Seed the random generator with random amount of millis()
gameRound = 0; // Reset the game to the beginning
while (gameRound < ROUNDS_TO_WIN)
add_to_moves(); // Add a button to the current moves, then play them back
playMoves(); // Play back the current game board
// Then require the player to repeat the sequence.
for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++)
byte choice = wait_for_button(); // See what button the user presses
if (choice == 0) return false; // If wait timed out, player loses
//gameBoard is like simonsColors in the previous example.
if (choice != gameBoard[currentMove]) return false; // If the choice is incorrect, player loses
delay(1000); // Player was correct, delay before playing moves
return true; // Player made it through all the rounds to win!
Finally, now that you’ve seen the code – go to the live github page and find out how to access the secret features of your Simon.
Have thoughts? Feedback? Let us know!
Want the educational materials (pre/post) we used as well? Check out Andrea’s post on her website!