AP CSP CodeX - Mission 10: Reaction Time

Mission 10 Lesson Plan

Mission 10: Reaction Time

Students use the CodeX internal clock to build a reaction time tester, and write functions to keep their code short and readable.

⏰ 45 min 🎯 Grades 9-12 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

During this mission, students use the CodeX internal clock to measure how fast they can react. They display a countdown, wait for a button press, and use time.ticks_ms() and time.ticks_diff() to calculate the elapsed time. Along the way they write functions to follow the DRY idea: never write the same code twice. After Objective 7, students create at least one more function from the main program to make it easier to read.

🎯 Mission Goal: Students will use CodeX's internal clock to create a device to measure reaction time.

🎯

Learning Targets

  • I can write a function to make code more efficient and readable.
  • I can utilize multiple variables in a new program and describe their purposes.
  • I can use functions from the time library to calculate reaction time.
💡

Key Concepts

  • Computers are driven by internal clocks.
  • Use the time.ticks_ms() function to record the current computer time.
  • Debounce the button press to detect only the most recent button press.
  • The DRY concept. Never write the same code twice!
✅

Assessment Opportunities

☑️

Success Criteria

  • Display a countdown
  • Clear the screen
  • Clear the pixels
  • Create a function for the wait_button
  • Use the start time and end time to calculate the elapsed time
  • Display the reaction time
📁

Digital Resources

🧰

Classroom Materials

  • ▸CodeX
  • ▸USB-C cable
  • ▸Computer
🌍

Real-World Applications

⏲️This mission utilizes the internal clock of a physical computing device. One use for the internal clock is an automatic timer. You find them in homes, factories and outdoor systems to save energy and add safety. Some examples are:
  • Outdoor and porch lighting
  • Coffee makers
  • Home security
  • Irrigation systems
  • Livestock feeding
🚀

Extensions & Cross-Curricular

ExtensionAdd a best score. Keep the fastest reaction time and display it when a player beats it.
ExtensionChange the pixel color based on the result, such as green for a fast reaction and red for a slow one.
ExtensionRun the test five times and display the average reaction time.
MathThe reaction time is measured in milliseconds. Convert the results to seconds, then find the class average for ten trials.
ScienceResearch how long it takes a signal to travel from your eye to your brain to your hand, and compare it to your reaction time results.
Lang ArtsWrite directions a classmate could follow to run a fair reaction time test.
🔤

Vocabulary

▾
Computer clock - Electronic clock circuits; the heartbeat of the computer. It is used in the sleep() function, scheduled activities within the CPU, and everything time related on the computer.
🐍

New Python Code

▾
pixels.set([BLACK, BLACK, BLACK, BLACK])Turn off all pixels using a list.
pixels.set([GREEN, GREEN, GREEN, GREEN])Turn all pixels a color using a list.
display.clear()Clear the CodeX display.
start_time = time.ticks_ms()Get current clock time.
reaction_time = time.ticks_diff(end_time, start_time)Find the difference between two clock times.
buttons.was_pressed(BTN_A)Reset the button state.
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-12 3A-AP-13 3A-AP-14 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-21

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-06 3B-AP-10 3B-AP-14 3B-AP-16 3B-AP-22 3B-AP-23

AP CSP Framework

DAT-2.A - Describe what information can be extracted from data.
AAP-3.D - Select appropriate libraries or existing code segments to use in creating new programs.
AAP-3.E - Write expressions to generate possible values, and evaluate expressions to determine the possible results.
Computational Thinking Practice 3.A - Generalize data sources through variables.
Computational Thinking Practice 4.C - Identify and correct errors in algorithms and programs, including error discovery through testing.
📝
Preparing for the Lesson
  • The assignment is best completed digitally. Prepare the assignment to give through your LMS.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
  • Decide on a warm-up topic that your students may need to review, such as functions or common programming errors.

🧑‍🏫
Teacher Notes
  • Encourage the students to do as much code on their own as they can, and use CodeTrek to check their work, or as a hint when needed.
  • The assignment adds an extra step to complete after Objective 7, before turning in the program.
  • If you have time at the end of the lesson, use the Mission 10 Kahoot! Review.
  • Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions, and additional information.
🗺️

Lesson Outline

This outline gives the narration for one way to present the lesson.

🗣️Warm-up

There is no specific warm-up for this lesson. As a teacher, decide on a topic that may need review with your students before starting the mission. You may want to review functions, or you can go over common programming errors. Keep it to a quick review and then get right to the mission.

💻Activity - Mission 10

Randomly group students into pairs for pair programming (or they can work individually).

Students log in to one computer. Two computers can be used if they want to have the assignment open on one computer and CodeSpace on the other computer.

Students go to make.firialabs.com and should be at the beginning of Mission 10.

Teaching tip - Objective 1: The objective reviews random numbers and the argument for randrange. There are some questions students need to answer on the assignment document. They should read the instructions carefully.
Teaching tip - Objective 2: This objective is also a review: displaying a countdown. Students create a function for this instead of typing directly in the main program.
Teaching tip - Objective 3: This objective has students use import time instead of from time import sleep. This means whenever they use sleep in their code, they need to use time.sleep(). If they are getting errors, be aware of this.
Teaching tip - Objective 6: Students create a function for the wait button. This is similar to the kill switch but does the opposite: wait for the button press before beginning. It is used twice in the code, so the instructions talk about reducing repetition by creating a function. This is a good concept to reinforce, a reason for functions and also an example of abstraction.
🧩Activity - After Objective 7
Teaching tip - After Objective 7: The students are asked to create at least one more function from the main program to increase the readability of the program.

✅ The assignment is complete and ready to turn in.

🧑‍🤝‍🧑Wrap-Up

Optional. Use a formative assessment for the wrap-up.

Formative assessment:

  • Daily reflection journal
  • Mission 10 Kahoot! Review (in class or individual)
  • Exit ticket or group review on functions, local variables, or loop conditions