AP CSP CodeX - Mission 6: Heartbeat (Obj. 1-7)
Mission 6: Heartbeat (Obj. 1-7)
Students use an infinite loop to animate a beating heart on the CodeX, then add a kill switch to stop the program.
Overview
In Mission 6, students give the CodeX a beating heart. They use images and the sleep command to animate a heartbeat, then put that code in an infinite while True: loop so it repeats forever. Students learn how to stop an infinite loop with a "kill switch" that breaks out of the loop when a button is pressed, and they use the debugger to step through the code. After Objective 7, students save the program as Heart2_functions, put the heartbeat code in a function, and call that function in the loop.
🎯 Mission Goal: Students will use images in an infinite loop to create a beating heart animation.
Learning Targets
- I can create an infinite loop to make my code more efficient.
- I can code a "kill switch".
Key Concepts
-
Infinite loops - when a condition is always
True. - A function can be used anywhere, including the code in an infinite loop.
- Readability is very important in coding. Whitespace can help, and comments are essential.
Assessment Opportunities
- Mission 6 Obj 1-7 Assignment
- Heart2_functions program (through Obj. 7)
Success Criteria
- Create a program that shows a beating heart using an infinite loop
-
Include a "kill switch" to stop the program (
BTN_U) - Create and call a function for the beating heart animation
Digital Resources
- ▸Mission 6 Obj 1-7 Assignment
- ▸Code Solutions and Assignment Answers - Teacher Dashboard > Educator Resources button
- ▸Mission 6 Kahoot Review (Questions 1-9)
Classroom Materials
- ▸CodeX
- ▸USB-C cable
- ▸Computer
Real-World Applications
Extensions & Cross-Curricular
pics.HAPPY or pics.MUSIC, to make a different animation in the loop.
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
- 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.
- Mission 6 may take a little over a class period, so it is divided into two lessons.
- After Objective 7, students continue with the code to create and use a function. This goes beyond the instructions in CodeSpace. Students can stay in Obj. 7 or move to the sandbox. Before creating the function, we recommend saving the program with a new name to keep the original code. This step is not vital to the program.
- If you have time at the end of the lesson, use the Mission 6 Kahoot Review. The first nine questions are covered in Objectives 1-7. You can hold off on the rest of the review until after Mission 6 is completed.
- 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.
Use a discussion strategy, like journaling, working at boards, selecting random students, or a form of think-pair-share.
Ask students if they have seen flashing road signs. Can they think of other continuously blinking or repeating indicators? How would you make something repeat forever with code?
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.
Students go to make.firialabs.com and should be at the beginning of Mission 6.
#TODO with the actual code for displaying a small heart. It does not show the code for that.while True: loop (not the button press). Then they call the function in the infinite loop. Students should be able to do this step on their own. We recommend doing a "Save As" and renaming the file Heart2_functions, but if they do not, that is okay. After creating the function, students also change the kill switch from BTN_A to BTN_U. In the next part of Mission 6, students will program BTN_A to do something else, and they will want to keep the kill switch. Students should test their code and debug any errors before submitting and going to the next lesson.✅ The assignment is complete and ready to turn in. You can decide if you want students to turn in the program up to this point, or wait until the end of Mission 6.
Use a formative assessment for the wrap-up.
Formative assessment:
- Daily reflection journal
- Mission 6 Kahoot Review, questions 1-9 (in class or individual)
- Exit ticket on loop, while loop, or infinite loop
- Group review on loops