During the summer after first year I entered the EngHack Hackathon held at the University of Waterloo with Will Clark, a fellow Mechatronics Engineering student and close friend. Together we built a Simon Says game that can be played between buttons and LEDs on a breadboard and an
iPhone. The user creates a sequence of the four colours using their device (breadboard or phone) which is then sent to
their opponent’s device and played back. If their opponent successfully repeats the sequence, they are prompted to create
their own sequence to send back to the user. After each round the length of the sequence increases until one player
makes a mistake, leaving the other player victorious. After the hackathon we continued working on the project so that
now, at any point during gameplay, the iPhone user can send messages to the breadboard user (which are output in Morse
code via a buzzer and LED) and the breadboard user can send Morse code messages to the iPhone user as well.
The video above provides a fairly detailed explanation of how everything works, here I will only provide a brief synopsis. The LEDs and buttons are connected to an Arduino which displays the sequence the user is to repeat, validates their input and then collects their new sequence. This sequence is converted into a byte array and sent using the serial protocol over a USB cable to a Raspberry Pi. The Arduino code is entirely non-blocking so that we could implement button debouncing and perform other time dependent operations (ie. Morse code output) without interfering with each other.
The Raspberry Pi acts as the communication link between the Arduino and the server, transmitting data via the SocketIO protocol to the Node.js server we have running on a Heroku server. The server also updates a monitoring interface that we coded using HTML, CSS and JavaScript to show the transmissions between the iPhone and Raspberry Pi. The server then broadcasts this information to the iPhone, and the same process occurs in the opposite direction once a response is received from the iPhone. The Python code uses multithreading so that a connection can be established and the code can wait for a server transmission on a separate thread from the main program, speeding up communications and gameplay significantly. The iPhone app is programmed in Swift and features a pleasant GUI for gameplay (see pictures). The squares light up to display the sequence and are used as buttons for input. The app also displays all messages between platforms in a familiar, intuitive manner.
To manage all the code contributions from the various platforms we implemented Git version control software. This allowed us to push code from any device to a central repository, revert to previous versions of the code if we made mistakes, and create branches off the main repository to test new features and then merge them back to the master branch once complete. We learned a lot about the Git workflow and the Simon Says repository is available for viewing on my Git Hub account if you're interested.