MISSION OBJECTIVE
Learn how to build a Game Controller and program the code for a game that uses (x,y) coordinates.
The Earth team has lost connection to a mining ship on Pipax, but our scientists have scrambled to get a primitive view and mining control back up! In this mission, code a game where ore randomly appears and use your Controller to play.
View student interface at make.playpiper.comMISSION CHARACTERS
MISSION MATERIALS
Computer with USB port and Chrome or Edge browser
Piper Make Base Station or Starter Kit
Game Controller
MISSION RESOURCES
Learning Goals
- Students will create hardware using tools such as a screwdriver.
- Students will review key electronics understandings, including wire and pin positions for specific inputs and outputs.
- Students will practice the computational concepts of
- Loops: Running the same sequence multiple times.
- Events: While a pin’s condition is on or off, another action happens.
- Students will create programs that use variables to store and modify data.
- Students will create programs that include events, loops, and conditionals.
- Students will practice organizing problems into smaller, manageable tasks.
- Students will create programs by incorporating smaller portions of existing programs to develop something new or add more advanced features.
- Students will test and debug a program or algorithm to ensure it accomplishes the intended task.
Career Connections
Software Quality Assurance Analyst: Salary $99,620/yr
Web and Digital Interface Designer: Salary $83,240/yr
Computer User Support Specialist: Salary $71,530/yr
Video Game Designer: Salary $83,240/yr
Hardware Diagram
Code Diagram
Tutorial Steps
Frog FrenzyClick NEXT.
This block tells the Pico that a Controller is connected to it, and it tells the Pico which pins it's connected to.
Choose the following options for the pin variables on the setup controller block:
- data pin: 2
- latch pin: 3
- clock pin: 4
Grab a repeat forever block from the Loops menu and connect it below the setup controller block. Then, grab an if do else block from the Logic menu and place it inside the repeat forever block.
Change the 0.5 on the repeat forever block to 0.1. Next, grab a read controller buttons block from the Sensing menu and place it into the repeat forever block.
Now, grab a was controller block from the Sensing menu and place it into the input of the if do else block. Drag out a turn pin block from the Chip menu and place it into the first do of the if do else block. Change the pin to 25 (LED).
Right-click the turn pin block and select duplicate. Move the new block into the else do part of the if do else block. Change it from ON to OFF:
Delete the repeat forever block and all the blocks inside it by dragging them to the trash can.
You just clicked STOP, and usually your Pico would stay connected. However, this time it disconnected itself. Why is that?
There are a few devices and pieces of code that require a full reset of the Controller when you are done running them. This clears some memory inside the Pico that the Controller was using so that it's ready to go again the next time you need it.
Because the Controller utilizes additional resources inside the Pico, you may need a few troubleshooting tips if your Pico stops connecting or running the programs properly on your computer.
Here are some things you can try if something doesn't work correctly:
- Check your program and wiring to make sure they are correct.
- Unplug your Pico, wait 5 seconds, and plug it back in.
- Refresh your browser page.
Our game will be simple - we will be able to move our character around using the Controller. The goal is to obtain the food while an enemy character chases our character. That's it, but it will be a lot of fun to play!
Our game will need to keep track of the positions for 3 things: our character, the food, and the enemy. Each character will have a horizontal position (left-right), which we will call x, and a vertical position (up-down), which we will call y. This means that we will need 6 variables to keep track of the positions of our 3 characters.
We will also need to keep track of the game's score. Our characters will gain one point every time they reach the food, and they will lose one point if the enemy catches them.
Let's create all 7 variables. Click the Variables menu, and then click the Create variable... button. You'll do this 7 times, and make each of the following variables:
- player x
- player y
- food x
- food y
- enemy x
- enemy y
- score
Click the Variables menu and grab the set block. Connect it below the setup controller block. Ensure the variable in that block is set to score. Grab a 0 block from the Values menu and place it into the set score block.
Right-click the set score block and select duplicate. Place the new block right below the set score block. Change the variable in the new block to "player x". Do this again and change the new block's variable to "player y". Repeat this two more times and set the two new blocks to "enemy x" and "enemy y". Finally, change the value in the enemy x block from 0 to 15, and change the value in the enemy y block from 0 to 9:
Next, grab a random integer block from the Values menu and place it into the set food x block. Change the 1 to 0, and change the 100 to 15. Grab another random integer block and place it into the set food y block. Change the 1 to 0, and change the 100 to 9:
- read the inputs
- move the characters
- check for collisions or hits
- check for scoring
- display the characters and score
- repeat!
Look carefully at the image below. The Console has columns and rows. We sometimes refer to the column as how far left or right a letter or number is in the Console, and we sometimes say that is the letter or number's x-position.
The Console also has rows, referring to how far up or down a letter or number is in the Console. This is also called the y-position.
When we write the position of a letter or number, we write it as two numbers like this: "(x,y)"
Click NEXT.
When the up button is pressed, we want the player character to move up 1 position, which means that we need the player y variable to decrease by 1. We also want to ensure that the player y variable never falls below 0 or exceeds 9, so that it stays inside the Console. We will do this by subtracting 1 from the variable and using a constrain block to keep the value from going out of bounds.
Drag out a set block from the Variables menu and place it into the if do block. Change the variable to player y. Next, grab a constrain block from the Logic menu and place it in the input of the set player y block. Then, grab a _ + _ block and place it into the first input of the constrain block. Grab a player y block from the Variables menu and place it into the left side of the _ + _ block. Grab a 0 block from the Values menu, place it into the right side of the _ + _ block, and change the 0 to a 1. Next, change the + (plus) to a - (minus). Finally, change the 50 in the constrain block to 9:
Right-click the if do block and select duplicate. Place the new if do block under the first one. Next, change the up button to down button, and change the - (minus) to a + (plus).
Then, duplicate the first if do block again and attach it below the last if do block. This time, change the up button to left button, change the two player y variables to player x, and change the 9 to 15.
Finally, duplicate the last if do block and attach the new block below the last if do block. Change the left button to right button and change the - (minus) to a + (plus):
Grab a to do something block from the Functions menu and place it to the right side of your program. Change the name of the function to "move enemy". Drag an if _ = _ do block out of the Logic menu and place it in the to move enemy block.
Click the blue gear icon. In the mini-workspace that opens up, grab the else if block and connect it below the if doblock to add an else if. Then, click the blue gear icon to close the mini-workspace.
Grab an enemy x block from the Variables and place it on the left side of the _ = _ block. Then, grab a player x block from the Variables and place it on the right side of the _ = _ block. Change the = (equals) to a < (less than).
Finally, grab a change block from the Variables menu and place it into the first do of the if do block. Change the variable to enemy x, and change the 1 to 0.5:
Right-click the _ < _ block and select duplicate. Place the new block into the else if input. Change the < (less than) to > (greater than).
Right-click the change enemy x block and duplicate it. Place the new block into the other do of the if do else if block. Change the 0.5 to -0.5 (negative):
Grab a to do something block from the Functions menu and place it to the right side of your program. Change the name of the function to "set up game".
Grab the repeat forever block and disconnect it from the program by dragging it straight down a little. Next, grab the set player x right after the set score block near the beginning of your program and place it into the to set up game block:
Grab a player x block from the Variables menu and place it into one of the inputs of the _ = _ block. Then, grab a round block from the Values menu and place it into the other side of the _ = _ block. Change the round to round down. Finally, grab an enemy x block from the Variables menu and place it into the input of the round down block:
Grab a change block from the Variables menu and place it into the if do block. Make sure it is set to the score variable and then change the 1 to a -1 (negative). Finally, grab a set up game block from the Functions menu and connect it below the change score block:
If the player's position is the same as the food's position, then the player has obtained the food and earns a point. After the player receives the food, we also want to reset the game.
Grab a to do something from the Functions menu and place it on the right side of your program. Change the name of the function to "check food". Then, grab a check food block from the Functions menu and place it into the repeat forever block:
Grab a player x block from the Variables menu and place it into one of the inputs of the _ = _ block. Then, grab a food x block from the Variables menu and place it into the other side of the _ = _ block.
Right-click the _ = _ block and select duplicate. Place the new blocks into the other side of the and block. Change player x to player y and food x to food y in the new blocks:
Grab a to do something block from the Functions menu and place it to the right side of your program. Change the name of the function to "print game". Then, grab a print game block from the Functions menu and place it into the repeat forever block:
Next, we need to print out each character. We can do this by setting the cursor position first and then printing a letter for each character.
Grab a console set cursor position block and connect it below the console clear block. Delete the two 0 blocks in the console set cursor position block by dragging them to the trash can.
Now, grab a player x block from the Variables menu and place it into the x input of the console set cursor block. Then, grab a player y block and place it into the y input. Next, grab a print without new line block from the Chip menu and connect it below the console set cursor block. Finally, type an O into the "_" block:
Let's print the food next. Right-click and duplicate the console set cursor block and connect it below the print without new line block. Change the player x and player y to food x and food y. Then, right-click and duplicate the print without new line block and connect it below the console set cursor block. Finally, change the O to a *:
Delete the food x and food y by dragging them to the trash can. Then, right-click and duplicate the print without new line block and connect it below the last console set cursor block. Change the * to an X:
Next, grab an enemy x block from the Variables menu and place it into the first round down block. Then, place an enemy y block into the second round down block:
Grab a console set cursor block from the Chip menu and connect it below the last print without new line block. Change the first 0 to 18 and change the second 0 to 5. Then, grab a print without new line block from the Chip menu and place it below the last console set cursor block.
Now, type "Score: " into the "_" block. Notice the extra space at the end of "Score: ". Then, grab another print without new line block from the Chip menu and place it below the last print without new line block. Delete the "_" block. Then, grab a score block from the Variables menu and place it into the print without new line block:
How high of a score can you get?
When you are finished playing your game, click STOP and then click NEXT.
Blueprint
OPEN IN BLUEPRINT VIEWER DOWNLOAD
Have an different version? Look for more information on the Support Page.
Troubleshooting Tips
-
Is your Pico disconnecting after you test the Controller?
- Check the program and wiring to make sure they are correct. The wires sent with your Game Controller might be different colors than depicted, which is fine. Follow the diagram to make the right connections.
- Unplug your Pico, wait 5 seconds, and plug it back in.
- Refresh your browser page.
Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly.
View Support Docs or Contact Support
EXPANDED RESOURCES
Term Glossary
Console Personal computers built for gaming (e.g., PlayStation, Xbox, Nintendo Switch).
Modding Making "modifications" to how a game sounds, plays, looks, or functions, usually by users.
Graphic User Interface (GUI) A way to display information on the computer screen where the user can use a mouse or touchscreen to click various buttons. (CAT)
Playtesting Playing through new inventions or builds to find bugs, test their ease of use, and get new ideas to build on.
Virtual Reality (VR) Computer technology that makes someone feel like they are elsewhere. It requires a player to wear a headset and use input devices to play games.
Standards Alignment
ISTE Framework Game Controller Standards Alignment

