REACTION GAME

PIPER MAKE EDUCATOR RESOURCES SERIES

To do this project, you will need a Piper Make Starter Kit. Get yours here:

It's a race of the reflexes to see who can hit their button the fastest!

To get started, head to Piper Make and hit this icon:

Time: 30 minutes

Age Range: 8+

Difficulty: Intermediate

In this project, students design a game of skill that they may play against each other. Each player will race to press their button the fastest after the light turns on.

Note: There are step by step instructions for the students to follow in the tutorials included in each project on Piper Make. These provide directions both for writing code and for building the electronic circuits. The tutorials are well-defined and most students will be able to follow them with little assistance required.

LEARNING OBJECTIVES

Students will:

 

  • Build a head-to-head game of skill and program selection of a winner
  • Coding Skills: Procedures, Timer, Sequences, Variables
  • Practice coding loops
  • Review these key electronics understandings:
    • Binary state of a button as an input
  • Practice computational concepts of
    • loops: running the same sequence multiple times
    • events: while a pin’s condition is on or off, another action happens
  • Create programs that use variables to store and modify data.
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.
  • Perform different roles when collaborating with peers during the design, implementation, and review stages of program development.

STANDARDS ALIGNMENT

CSTA's K-12 Standards 

1B-AP-09: Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10: Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11: Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12: Modify, remix, or incorporate portions of an existing program into one’s own work, to develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15:Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

CCSS ELA

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

World-Class Instructional Design and Assessment (WIDA) English Language Proficiency Standards

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

  • Interpret scientific arguments by
  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

California's K-12 Computer Science Standards

3-5.AP.11: Create programs that use variables to store and modify data. (P5.2)

3-5.AP.12: Create programs that include events, loops, and conditionals.

3-5.AP.13: Decompose problems into smaller, manageable tasks which may themselves be decomposed. (P3.2)

3-5.AP.14: Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features. (P4.2, P5.3)

3-5.AP.17: Test and debug a program or algorithm to ensure it accomplishes the intended task. (P6.2)

Common Core English Language Arts

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

California English Language Development Standards

CA ELD.3.C.11: Supporting own opinions and evaluating others’ opinions in speaking and writing

CA ELD.3.C.12: Selecting and applying varied and precise vocabulary and language structures to effectively convey ideas

Michigan Integrated Technology Competencies for Students (MITECS)

1B-AP-09: Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10: Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11: Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12: Modify, remix, or incorporate portions of an existing program into one’s own work, to develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15: Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

Michigan English Language Arts

Michigan ELA, Grade 3-8, Research, 8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

Michigan ELA, Grade 3-8, Range of Writing, 10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

WIDA English Language Development

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

  • Interpret scientific arguments by
  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

Science Texas Essential Knowledge & Skills Grade 3

(b)(2) Scientific investigation and reasoning. The student uses scientific practices during laboratory and outdoor investigations. The student is expected to:
(A) plan and implement descriptive investigations, including asking and answering questions, making inferences, and selecting and using equipment or technology needed, to solve a specific problem in the natural world;

(b)(3) Scientific investigation and reasoning. The student knows that information, critical thinking, scientific problem solving, and the contributions of scientists are used in making decisions.

Science Texas Essential Knowledge & Skills Grade 4

(a)(1)(A) Within the physical environment, students know about the physical properties of matter including mass, volume, states of matter, temperature, magnetism, and the ability to sink or float. Students will differentiate among forms of energy including mechanical, light, sound, and thermal energy. Students will explore electrical circuits and design descriptive investigations to explore the effect of force on objects.

(b)(3) Scientific investigation and reasoning. The student uses critical thinking and scientific problem solving to make informed decisions. The student is expected to:

    (A) analyze, evaluate, and critique scientific explanations by using evidence, logical reasoning, and experimental and observational testing;

    (B) represent the natural world using models such as the water cycle and stream tables and identify their limitations, including accuracy and size; and

    (C) connect grade-level appropriate science concepts with the history of science, science careers, and contributions of scientists.

Science Texas Essential Knowledge & Skills Grade 5

(a)(1) In Grade 5, scientific investigations are used to learn about the natural world. Students should understand that certain types of questions can be answered by investigations and that methods, models, and conclusions built from these investigations change as new observations are made. Models of objects and events are tools for understanding the natural world and can show how systems work. They have limitations and based on new discoveries are constantly being modified to more closely reflect the natural world.

(a)(3) Recurring themes are pervasive in sciences, mathematics, and technology. These ideas transcend disciplinary boundaries and include patterns, cycles, systems, models, and change and constancy.

ELA Texas Essential Knowledge & Skills Grade 3

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) speak coherently about the topic under discussion, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively;

    (D) work collaboratively with others by following agreed-upon rules, norms, and protocols; and

    (E) develop social communication such as conversing politely in all situations.

ELA Texas Essential Knowledge & Skills Grades 4 & 5

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) express an opinion supported by accurate information, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively; and

    (D) work collaboratively with others to develop a plan of shared responsibilities.

(b)(13) Inquiry and research: listening, speaking, reading, writing, and thinking using multiple texts. The student engages in both short-term and sustained recursive inquiry processes for a variety of purposes. The student is expected to:

    (A) generate and clarify questions on a topic for formal and informal inquiry;

    (B) develop and follow a research plan with adult assistance;

    (C) identify and gather relevant information from a variety of sources;

    (D) understand credibility of primary and secondary sources;

    (E) demonstrate understanding of information gathered;

    (F) differentiate between paraphrasing and plagiarism when using source materials;

    (G) develop a bibliography; and

    (H) use an appropriate mode of delivery, whether written, oral, or multimodal, to present results.

§74.4. English Language Proficiency Standards

(c) Cross-curricular second language acquisition essential knowledge and skills.

(3) Cross-curricular second language acquisition/speaking.

(D) speak using grade-level content area vocabulary in context to internalize new English words and build academic language proficiency;

(E) share information in cooperative learning interactions;

(F) ask and give information ranging from using a very limited bank of high-frequency, high-need, concrete vocabulary, including key words and expressions needed for basic communication in academic and social contexts, to using abstract and content-based vocabulary during extended speaking assignments;

(G) express opinions, ideas, and feelings ranging from communicating single words and short phrases to participating in extended discussions on a variety of social and grade-appropriate academic topics;

(H) narrate, describe, and explain with increasing specificity and detail as more English is acquired;

CONCEPTS

 In this project, students will learn to program functions / procedures, a key skill for programming. Other key skills in this project include timer, sequences and variables.

PARTS

Raspberry Pi Pico, breadboard, charging cable, M2M Blue Jumper Wire, M2M Red Jumper Wire, M2M Black Jumper Wire, Red LED, 330 Ω Resistor, Small Tactile Button

GPIO SETUP

none

OVERVIEW OF STEPS

Step 1: Ready to play?

Warm up your fingers my friends, because in this project we’ll be testing those lightning fast reflexes!

Let’s build a game where you and a friend can see who has the fastest reaction time!

Click NEXT to get started.

Reaction Game

Step 2: Get your electronics

Let’s start by gathering our supplies. You’ll need your Pico and breadboard, an LED of any color, a single 330 Ω resistor, two push-button switches, and three jumper wires.

Reaction Game

Step 3: Wire your LED

Here’s how the game works. An LED will flash on at a random moment, and the first person to hit their button wins!

To start, let’s build our LED that will signal the start of the game.

First connect one end of a jumper wire to GP15 and the other a few rows down. Push the leads of the LED into the same row straddling the center gap, Make sure that the longlead of the LED (the anode) is on the side of the breadboard with the jumper wire connected to GP15.

Connect a resistor from the row with the shortlead of the LED to the GROUND rail. Then, connect the GROUND rail to a ground (GND) pin on the Pico with another jumper wire.

Check out the Blink tutorial if you have any questions!

Once you've added your LED, click NEXT.

Reaction Game

Step 4: Wire your push buttons

Reaction Game

Next, let’s add the push buttons that you’ll be competing with!

Go ahead and add the push buttons as shown in the picture below.

Connect one of the buttons to GP14 and the other to GP13. Make sure you connect the other side of each button to the GROUND rail. Remember, when you press down the button, the GPIO pin will detect the drop in voltage as an INPUT.

Click NEXT when you finish adding your buttons.

Step 5: Wiring is done!

Reaction Game

Now let’s write some code to create our game! Let’s think about how we want the game to run.

First, we want our LED to turn on at a random time. How do we code that?

Start by dragging a start block from your Chip menu, followed by the turn pin ON block. Change the pin number variable to GP15 (where your LED is connected).

But wait! We don’t want our LED to immediately turn on, right? Let’s add a wait block in there. Drag a wait block from the Chip menu and connect it between the start and turn pin blocks.

You’ll notice that a time is automatically set to 1 second. However, if we know the time the LED will turn on, we might just count down in our heads instead of playing the game.

Click NEXT to learn how to make the wait time random.

Step 6: Write the code

To make the wait time random, let’s use the random integer block in the Values menu, and drag it into the wait step.

This will cause the number block to "pop-out" - you can just drag that block to the trash can.

The leftover number block might be behind your program - just drag your whole program by grabbing the start block to move it and see what might be underneath it.

The random integer block returns a random number from the range you provide, so go ahead and put in the minimum and maximum number of seconds you want to wait for the LED to come on.

A good range is between 3 and 8 seconds, so we don’t get too impatient.

Click NEXT.

Reaction Game

Step 7: What's your function?

Okay so now we have our LED turning on, and we’re ready with our fingers on the buttons. But how can we get the code to detect which button is pressed first?

To do this, we’re going to write a Function. A function is a set of code that will run and return (send back) a value—in our case, the winner!

Drag out a to "do something" - return block from the Function menu and change the name of the function to “determine winner”.

Click NEXT.

Reaction Game

Step 8: Send it back!

Reaction Game

The first thing to think of when creating a function is what it will return. In this case, we want to know who pressed the button fastest, so we’ll want our function to return the name of the player who won!

To start, let’s create a variable (from the Variables menu) and call it “winner”. Then, drag the winner block and place it as the return of your function, so that it can be printed when the game ends.

Click NEXT.

Step 9: Setup the ifs

To figure out what that winner variable should be set to, we’ll need to check whether player 1 or player 2 pushed down their button.

To do this, let’s write an if-else if statement. This will test which, if any, button is pressed.

Drag an if-do block from the top of the Logic menu into your "determine winner" function block to get started.

We still need to turn the if-do block into an if-else if block. To do this, click the small blue gear icon on the if-do block. This will bring up a new menu that lets you change the shape of the if block:

In that menu, drag an else if block over to the if block and connect it. Clock the blue gear icon again to close the menu.

Click NEXT when your if-else if block is ready.

Reaction Game

Step 10: Checking in

Remember we want the code to do the following: if the button connected to GP14 is pressed, we want “player 1” to be saved to our winner variable. Otherwise, if the button connected to GP13 is pressed, we want “player 2” to be saved to the winner variable. How would you code that?

Click NEXT to find out!

Step 11: Looking for button presses

Drag out an is pin LOW when pulled UP block and add it to the first test of our if-else if block. Change the pin number variable to 14.

Duplicate the is pin block for the else-if test. Change that pin number variable to 13.

Click NEXT.

Reaction Game

Step 12: Setting the variable

If the GP14 circuit completes, we want to set our variable to “player 1”—so drag a set winner to block from the Variables menu and place it in the first do statement.

Next, you'll need a "_" block from the Values menu. Grab one and drag it into the set winner to block.
Type “player 1” as the value into the "_" block.

Repeat all of the steps for player 2 below the GP13 test step.

When your blocks are ready, click NEXT.

Reaction Game

Step 13: Keep checking

But we want our code to be constantly looping, testing if either button is pressed and we want that process to be happening FAST!

Let’s add a loop function to the check steps. Drag out repeat forever block and change the wait time to 0.

Why zero? Well if we set it to 1 second, you might see the LED come on, both players press the button, and THEN the loop will execute, automatically making the first player in the loop, “player 1” the winner. Every time. Boo!

Instead, with the wait time set to zero, the loop happens so quickly that tiny differences in your reaction time are picked up!!

Click NEXT.

Reaction Game

Step 14: Exiting the loop

But we also want the loop to stop running when a button is pressed, right? Otherwise, we’ll never know who won!

To have the function return the winner value, we have to stop the loop from running using an exit loop block. So if player 1 hits their button, the winner variable will be set to "player 1" and the loop will be exited.

If play two hits their button first, then the same process should happen for player two in the if-else part of the block.

Drag out two exit loop blocks and add them to your function code like this:

Click NEXT.

Reaction Game

Step 15: Who won?

So let’s go back to our main code and code up the big reveal! Right now we have the LED coming on, but after that, we want to execute the function we’ve written. And ideally, because the function’s output is the winner—we want to print that in our console.

To do that, drag a print block from the Chip menu and add the output from the function to it.

Keep in mind, this MUST be the output from the function, so drag the determine winner block from the Function menu.

After that, go ahead and turn off the LED using a turn pin 15 OFF block:

 

Ready to try it out? Click NEXT.

Reaction Game
Reaction Game

Step 16: Play your game!

Now your code is ready to go.

Here's a reminder on how you play! An LED will flash on at a random moment, and the first person to hit their button wins!

Grab a friend and hit START to play! Who can hit the button fastest when the LED comes on?

Keep tweaking your game! Can you modify the messages that print? Can you add a third button so that three people can play at once? Is there a limit to how many buttons you could add?

Click NEXT.

Reaction Game

Step 17: You Finished!

Click EXIT to return to the menu and start your next coding challenge.