• 1
    Assembling the Hardware

    Gather both the client that you intend to build the Simon Says game with and all of the parts detailed in the parts list above.

    We are using an MCP23017 port expander to expand the number of I/O ports on the Builder Base by sixteen, however we will only be using nine of these extra ports.

    The port expander connects to the Builder Base through the SCL and SDA ports and communicates via I2C communication.

  • 2
    Build the Firmware

    Here we will build two sets of firmware files: one for the Button and the other for the LED.

    Using the toolbar located on the left hand side of the screen navigate to the firmware builder and then select “+ Create New” button to create a new firmware file.

    Next, name your firmware file “Simon Says” and hit “Create”.
    Now, click the “+ Add Hardware” button, and search for the device named “Button”.
    Name your device. We suggest naming this one “Red”. Add four more buttons by repeating these steps and name them: Blue, Yellow, Green, and Reset.
    To configure the “Red” button, click on it in the device list and select the “MCP23017” driver from the driver dropdown menu.

    Next, input:

    I2C: 0x27

    Channel: B0

    Pull Up: Disabled

    Now, repeat these steps for the rest of the buttons. The only configuration that will change between them is the Channel selected for each. Here is a table for all of the button configurations:

    With the buttons configured, let’s now add the LEDs. Again, click the “+Add Hardware” button, search for the LED device, and give it a name. Name the LED “Red LED”, and select the “Add Hardware” button.
    Add three more LEDs by repeating these steps and name them: Green LED, Blue LED, and Yellow LED.

    Click on the “Red LED” device and select the “MCP23017/8” driver under the driver dropdown menu.

    For this driver we will select:

    I2C Address: 0x27

    Channel: A0

    Mode: Initially low

    Now, repeat these steps for the rest of the LEDs. The only configuration that will change between them is the channel selected for each. Here is a table for all of the LED configurations:

    With the configurations set you can now save and upload your firmware.

  • 3
    Program the App

    For this project we will walk you through the objects used and the logic involved. You can choose to follow along, or you can download the app and import it onto your server.

    Once there, click “+ Create New”.

    Name your app, and hit “Create”.
    You will be redirected to the canvas where you can build the app.
    This first section consists of both a physical reset button and a dashboard button. Both perform the same function of initializing the “Store” array and triggering the game sequence.
    The Game sequence consists of indexing the “Store” Array to -1. This index will place the value input at the end of the array. The Random Number code object is then triggered. This picks a random number between 1 and 4. This value is then passed and written to the store array.
    After the value is written to the array, you can see that from trigger port 8 the “Store” Array Iterate object’s Index is reset and then from trigger port 9 the Loop object is triggered. Upon triggering, the Loop triggers the Array iterate object to output the values of the Array. These values are then passed to the “Illuminate LEDs” Any Data Sequence object. Once the end of the array is reached, the index on the Loop is reset.
    When the values are passed from the Array Iterate object to the Any Data Sequence object they are passed to a custom snippet named “Number to Color Translate”. The numbers that can be passed are 0-4. Each number corresponds to a different color. 1 is Green, 2 is Red, 3 is Blue, 4 is Yellow, and 0 outputs “false” from all output ports.
    You can see the code here:
      case 0:{
        return [false,false,false,false];
      }; break;
      case 1:{
        return [true,false,false,false];
      }; break;
      case 2:{
        return [false,true,false,false];
      }; break;
      case 3:{
        return [false,false,true,false];
      }; break;
      case 4:{
        return [false,false,false,true];
      }; break;
      default: break;

    The number passed to the snippet dictates which output port will send out a trigger signal. Once this signal is passed it will trigger the LED and Button interface objects that are connected to it.

    So, for example, if a 2 is passed to the custom snippet the second output port, and only the second output port, will send out a signal.

    Also connected to the output ports on the sequence are a timeout and static number objects. The purpose of this is to shutoff the LEDs once they have been triggered. The timeout allows the LED to stay on for 500ms before a 0 is sent to the “Number to Color Translate object” which turns off all output ports.

    That’s how the colors for the game are selected and stored. Now we will show you how the logic determines if the right sequence of color inputs have been selected by the user. 

    **It is important to note that these LED objects are used twice in this application, but due to the mapping they all correspond to the same LEDs

    Here we have all of the button hardware components connected to the LEDs. We configured this so that every time the user presses a button the corresponding LED will be illuminated. So if the user presses the button that corresponds to the green LED, the green LED will illuminate for the interval that the button is depressed.

    You can also see that the buttons are connected to a custom snippet. This is essentially the reverse of the other custom snippet used above. Each button is connected to an individual input port on the snippet. Depending upon which port the signal is received a number in the range of 1-4 is output by the snippet.

    You can see the custom snippet code here:

    return [trigger+1, new Date()]

     What this code does is return the number of the output port ([0,3] + 1) (to make it 1 through 4) that the signal was received from, and a “new Date()” which acts as a trigger. The number is output through the first output port, and the trigger through the second.

    These outputs are then used to verify that the input given is correct. For every button pressed the “Verify Sequence” data sequence is triggered. This triggers the Array Iterate object for the “Store” Array, passing the first value to the Value Compare object. The Value from the “Button to Number” custom snippet is also passed to the same Value Compare object. If the values are equal, the Value Compare object will send a signal to the Digital AND object below.

    Now if the Array Iterate object has reached the end of the list and all values entered match the values stored in the array, the Digital AND will trigger and the game sequence will be restarted.

    You can see this logic path with the lines selected in blue.

    **The “Value 1” port on the value compare object is set to “Trigger” under the properties panel. This is important as the comparison needs to be triggered every time a button is depressed.

    However, if one of the values entered is incorrect the “Greater” and “Less” output ports on the Value compare port will trigger.

    This then triggers the “Incorrect Pattern” data sequence. This sequence causes the LEDs to turn on and off in quick succession, and re-initializes the “Store” array; effectively priming the array for a new game.
    This sums up the basic logic behind the Simon Says project.