AP CSP CodeX - Mission 6: Heartbeat (Obj. 8-11)

Mission 6 Obj 8-11 Lesson Plan

Mission 6: Heartbeat (Obj. 8-11)

Students use a variable and float values in an infinite loop to speed up and slow down a beating heart with the CodeX buttons.

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

Overview

In this lesson, students finish Mission 6. They learn about the float data type, then use a variable to hold the delay between heartbeats. Pressing BTN_A adds to the delay to slow the heart down, and pressing BTN_B subtracts from the delay to speed it up. Pressing BTN_B too many times makes the delay negative, which causes an error, and students record that error in their assignment. After Objective 11 and the quiz, students go back to their code to create and call a function for adjusting the speed, and add code so the program does not crash.

🎯 Mission Goal: Students will use a variable and images in an infinite loop to create a beating heart animation.

🎯

Learning Targets

  • I can apply variables to a new program.
  • I can update the value of a variable using math.
  • I can program using float values.
💡

Key Concepts

  • Use a variable to hold the current state of your program. In this case it is the speed of the heartbeat, or to be specific, the delay between beats.
  • An infinite loop is a good way to continuously check for button presses, which lets the CodeX act on events as they occur.
✅

Assessment Opportunities

☑️

Success Criteria

  • Create a program that shows a beating heart using an infinite loop
  • Include code in the program that speeds up and slows down the heart
  • Create and call a function for adjusting the speed of the animation
  • Add code so the program does not crash
📁

Digital Resources

🧰

Classroom Materials

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

Real-World Applications

🚧Ask students if they have seen flashing road signs. Can they think of other continuously blinking or repeating indicators? How can computers make this more efficient?
🔘Students programmed an embedded computer to monitor push buttons to control speed UP and DOWN. That is real-world code used in many applications you see around you.
📺TV remotes, game controllers, push button light dimmers, and more.
🚀

Extensions & Cross-Curricular

ExtensionCreate a flowchart of the program.
🔤

Vocabulary

▾
Iteration - The repeating portion of an algorithm; code that repeats until a given condition is met or a specified number of times.
Increment - Increasing a variable by a specific amount. Often counters are incremented by one: count = count + 1, like a counter, but the value can be any literal number (or constant).
Decrement - Decreasing a variable by a specific amount. Often counters are decremented by one, like a countdown: count = count - 1, but it can be any literal number or constant.
🐍

New Python Code

▾
if buttons.was_pressed(BTN_A): delay = delay + 0.2Increment (with an if statement).
if buttons.was_pressed(BTN_B): delay = delay - 0.2Decrement (with an if statement).
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-01 3A-CS-03 3A-AP-13 3A-AP-15 3A-AP-17 3A-AP-18 3A-AP-21

CSTA Standards - Grades 11-12

3B-CS-02 3B-AP-10 3B-AP-14 3B-AP-16 3B-AP-17 3B-AP-22 3B-AP-23

AP CSP Framework

AAP-1.JCEvaluate expressions that use arithmetic operators.
AAP-1.JWrite iteration statements. Determine the result or side effect of iteration statements.
AAP-3.CDevelop procedural abstractions to manage complexity in a program by writing procedures.
Computational Thinking Practice 3.BUse abstraction to manage complexity in a program.
Computational Thinking Practice 4.CIdentify 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.
  • Have the Mission 6 Kahoot Review ready in case you have time at the end of the lesson.

🧑‍🏫
Teacher Notes
  • Start the lesson by having students open their program from the last lesson (Mission 6 Obj 1-7), Heart2_functions.
  • After Objective 11 and the quiz, students continue with the code to create and use a function. This goes beyond the instructions in CodeSpace. Students can stay in Obj. 11 or move to the sandbox. You can encourage your students to do this extension on their own, or give them the instructions for creating a function. This is all practice in preparation for the Create PT.
  • If you have time at the end of the lesson, use the Mission 6 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

Use a discussion strategy, like journaling, working at boards, selecting random students, or a form of think-pair-share.

Topic: Review what students have learned so far in Mission 6.

💻Activity - Mission 6 Objectives 8-11

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 activity guide open on one computer and CodeSpace on the other computer.

Students go to make.firialabs.com and start in Mission 6 at Objective 8. Students open their Heart2_functions program.

Teaching tip - Objective 8: Students learn another data type: float. A float is a decimal number. It is called "float" because the numbers have a decimal, or "floating point". You can have a short discussion about this if needed. Python is not very specific about integers and floats and the need to convert from one to the other. But other programming languages are very strict about data types, and data type conversion would have to happen for variables of different data types to work together. To convert a value to integer, use: int(). To convert a value to float, use: float().
Teaching tip - Objective 9: Review of variables. First introduced in Mission 3 (Light Show) Objective 8.
Teaching tip - Objective 10: The instructions in the assignment are slightly different from CodeTrek. Students have already changed the button used to break the loop. The goal says to "Remove break", but they should not do that!
Teaching tip - Objective 11: The code for this objective will cause an error. That is one of the goals to achieve. Students will record their error in the assignment. Then, after the objective, they will go to the sandbox and fix the error.
🔧Activity - After Objective 11
Teaching tip - After Objective 11: For practice with functions, students should create a function for the code that speeds up and slows down the heartbeat. Then call the function in the infinite loop. Students should be able to do this step on their own. Encourage students to do this on their own before reading the instructions on the assignment. Students are also asked to fix the error in the new function. One way to do this is described in the assignment, but there are other ways. Challenge students to come up with their own way to solve the problem. Students should test their code and debug any errors before submitting and going to the next lesson.

Extension: Create a flowchart of the program.

✅ The assignment is complete and ready to turn in.

🧑‍🤝‍🧑Wrap-Up

Use a formative assessment for the wrap-up.

Formative assessment:

  • Daily reflection journal
  • Mission 6 Kahoot Review (in class or individual)
  • Exit ticket on incrementing and decrementing
  • Exit ticket on data types
  • Group review on incrementing, decrementing, and data types