• 1
    Building the Hardware

    Gather all of the materials listed in the parts list above and we’ll start by connecting the LCD to the Builder Base.

    On the back of your LCD you should have four pins labeled SDA,SCL,VCC, and GND.

    You should use MF jumper wires to attach the LCD to the Builder base

    You should attach the LCD to the Builder Base as follows:

    The other hardware component that needs to be assembled is the Simon Says Project or the DIY Kit.

    If you don’t already have one of those circuits assembled, follow the steps listed on their pages.

    This circuit will serve as your game board for the Whack-a-Mole project.

    Once you have both circuits completed you can move onto building the Firmware.

  • 2
    Build the Firmware

    First we will start by building the firmware file for the LCD screen.

    Create a new firmware file and name it “Whack_a_mole_LCD”.

    Now, by using the “+Add Hardware” button, add an LCD to the firmware file.

    Now, select the “Generic LCD2004 Display (I2C) from the driver dropdown menu and configure the driver as follows:

    **The I2C address of your LCD might be different that ours, so when your LCD is connected to the Builder Base we suggest that you perform an I2C scan via the Debug menu on our clients page.**

    That’s it! Save your firmware file.

    Next, depending on which controller circuit you use, you should build the firmware file for either the Simon Says Project or the DIY Kit.

  • 3
    Build the Application

    We will use this section to walk you through the basic game logic involved in the Whack-a-mole game. You can either download the application from the resources section below, or you can follow along and build the game for yourself!

    Here we have split the application up into for main components:

    1. Main Game sequence, 2. Input, 3.Score/Win Calculation, 4. Output

    These two Input Number objects set the time a player as to react, and the number of points the player needs before the game is won. These values are set through the Dashboard.

    When the player hits the “Start” hardware button object a number of objects are triggered. First, the “Start” interface object is triggered. We have hardware and interface button objects here so that the game can be played from both the dashboard and the game controller.

    From the Start button the Digital Toggle object is then triggered, the toggle object then triggers the “And” object, which consequently triggers the “Sequence” object.

    The data sequence then triggers the RNG object, which will output a random number in the range [1,4]. The sequence will then trigger a 1s timeout. During this timeout the random number is sent to the “Color Enum Out” Custom snippet. This custom snipper takes in the range [0,4], and sends a trigger out of one port depending on the number received.

    Here’s the code for the object:

    Returning back to the original sequence, the RNG object also sends the number to the “Value 1” port of the Value Compare object.

    At this point the timeout block has finished executing its 1000ms timeout and sends a trigger to the “send zero” custom snippet, and it also triggers the Value Compare block.

    The Value compare Block evaluates the value that the RNG block produces against the color(number) that the player inputs.

    When we send a zero to the custom “Color Enum Out” snippet a trigger is sent out of its Reset port. This resets the game sequence and causes another color to be selected. The Sequence will either be reset by the timeout, or if the player selects the right color before the timeout executes.

    We will now look at the the Input portion of the program.

    We have a hardware and an interface button object for each color, this allows us to play the game from both the controller and the dashboard. These button pairs each feed into their corresponding ports on the “Color Enum In” custom snippet. This snippet converts the the port the signal is received from the port's corresponding number.

    This value is then passed to the Value Compare object that we discussed earlier. If the value that the player inputs is equal to the value that the RNG object generates, the game sequence is then reset. If the colors are not equal then nothing is triggered.

    We will now look at how the score is calculated and how a winner is determined.

    When the Game starts, the Data counter is set to 0, and the Max of the Data Counter is by default set to 10, but that can be changed through the dashboard.

    If the RNG value and the value that the player input are equal, the Increment port on the data counter is triggered. This Value is then passed to the String Merge Block. The String Merge Block merges the strings “Score:” and “(Value from Counter)”.

    The value from the counter is also passed to the “Your Score” Text block which displays your score on the dashboard, and to the Any Data Sequence object, which sends the same string to the LCD.

    The counter also passes this value to the value compare block. This compare block evaluates your current score against the set winning score. By default the winning score is set to 10, but it can be changed through the dashboard.

    If the two values are equal, the “Win” static string block sends the message “!WIN! !WIN!” to the “Your Score” text block, and to the Any Data Sequence block, which sends the same string, “!WIN! !WIN!”, to the LCD.

    When a winning score is met, the value compare block also resets the entire game so that it can be played again.

    That’s it for programming the App, save it and return to your applications page!