Arduino
state machine diagram

Description

Like most electricomechanical systems, the heart of our system is our microprocessor, in particular, our arduino. The Arduino contains all of the functionality of dispensing cards, rotating, taking sensory input from the user (i.e. the two reflectance sensors to hit and stand), and taking system information from limit switches as well as all of the logic of dealing cards and deciding how to react to given input from the user. In addition, the arduino code has logic to send and receive serial states from the raspberry pi. You can view all the current code here.

This system has evolved from a relatively simple system. Originally, the arduino was only responsible for rotating and dispensing cards. The logic for when do those tasks was handled by the raspberry pi (for more information, check out the Facial Recognition/Serial Section), so the arduino code consisted of two functions on top of the standard loop and setup functions, dispense card and rotate. At this point, the electrical system did not contain the necessary components to support user input, although this was going to implemented in a future iteration. However, a large change in our system came from reconsidering how all of the parts were interacting and how they lead to certain failure points (this is covered in the Facial Recognition/Serial Section). We decided that we could eliminate many of these failure points by moving more of the logic to the arduino.

While still maintain modular code design, we were able to implement functions for dealing cards (i.e. dispensing a given amount cards at the beginning of the game), rotating between players at different angles, etc. What lended itself to an ability to switch design directions quickly like this was our original focus on modular, extensible design, which is definitely a focal point of our code.

Things to keep in mind

  • C will automatically convert integers above 0 to true if you have functions that return booleans. Make sure when you're switching from sensors that use digital output like buttons to sensors that use analog output that you do not return booleans.
  • Focus on modular design and intelligent use of variables to make prototyping design decisions easier and quicker.