Teacher Resources: Python with Robots MS Mission 4-1
Animatronics Lesson 1: Infinite Loops
Students will use an infinite loop to constantly blink the user LEDs in a cool pattern.
Overview
Mission 4-1 introduces students to infinite loops and counter variables. Students learn to use a while True: loop to execute code continuously, increment a counter variable to step through CodeBot's user LEDs, and use an if statement to prevent an out-of-range error. They also use the CodeSpace debugger to visualize how a variable changes value as code runs.
π― Mission Goal: Students will write a SweepLEDs program that uses an infinite loop to continuously sweep CodeBot's 8 user LEDs in a pattern.
Learning Targets
- I can use a while True: infinite loop.
- I can increment a counter variable.
- I can use the debugger to track a counter variable.
- I can use an if statement to avoid an out of range error.
- I can reset a variable to its initial value.
Key Concepts
- While loops are used to execute an algorithm constantly.
- Increments (and decrements) are used for updating variables like counters.
- CodeBot has 8 user LEDs, numbered 0 through 7. If you try to turn on a user LED with a different number, you get an out of range error.
- The debugger and console panel can be used to track the value of a variable.
Assessment Opportunities
- Mission 4 Lesson 1 Log (digital)
- Submit completed program SweepLEDs
- Submit the program with extensions
- Mission 4 Obj. 1-3 Review Kahoot!
Success Criteria
- Use an infinite loop
- Use a variable to light a user LED
- Increment the variable to light the LEDs in sequence
- Use an if statement to check if the variable is a specific number
- Reset the variable to its initial value
Digital Resources
Classroom Materials
- βΈCodeBot
- βΈUSB cable
Real-World Applications
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
π
New Python Code
βΎ
π
Standards
βΎ
CSTA Standards β Grades 6β8
- Decide what materials you want to use for presenting the lesson. The slides can be projected on a large screen.
- Be familiar with the mission log assignment and the questions they will answer. Prepare the assignment to give through your LMS.
- You might want to have more practice problems for Objective 2. The mission log assignment gives three problems. You can prepare more code segments for students to practice with.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- Objective 3 uses the debugger to track the variable. This can be done together as a whole class. Use the debugger and a large display screen. Note that the loop doesn't stop at 7, there just aren't any more LEDs left.
- The debugger stops when an error occurs, and the value in the debug window will no longer show. Make note of the value before it disappears.
- Review the difference between = and ==.
- Students should refer to their data from Mission 3 Lesson 3 to help with moving forward and turning.
Lesson Outline
Slide 2 - Students can write in their log first and then share, or discuss first and then write in their log. These warm-up questions review code from Mission 3. Students can share their answers, or compare with each other. This code is used during the lesson.
- Question: What code turns on a user LED?
- Question: What code defines a variable for delay?
The Chrome browser works best, but other browsers also support CodeSpace. Each student will complete a Mission Log. Students could work in pairs through the lesson, or they can work individually.
ποΈ Optional: Mission 4 Obj 1-3 Kahoot! Review. A review Kahoot! is available for these three objectives. You can do the Kahoot together as a class, or assign it independently.
The post-mission reflection asks students to review the difference between == and =. You can use an extension or cross-curricular activity as post-mission activity.
End by collecting the Mission 4 Lesson 1 Log.