Teacher Resources: Python with Robots MS Mission 4-2
Animatronics Lesson 2: Counting Guests
Students count the number of guests using a button press and display the count using line sensor LEDs.
Overview
Mission 4-2 builds on the infinite loop from Mission 4-1. Students write a CountGuests program that uses a button press to increment a counter variable and display the count by turning on line sensor LEDs. They also add a speaker beep for each press and learn to debounce the button to prevent false counts.
🎯 Mission Goal: Students will write a CountGuests program that counts button presses, displays the running count using line sensor LEDs, beeps on each press, and breaks the loop when the count reaches 5.
Learning Targets
- I can increment a counter variable.
-
I can use
buttons.was_pressed()in an if statement to control program flow. - I can display a number using line sensor LEDs.
- I can break a loop.
- I can add a beep to a program.
- I can debounce a button press.
Key Concepts
- Increments (and decrements) are used for updating variables like counters.
- Button presses (inputs), LEDs (outputs) and speaker sounds (outputs) are part of the user interface. They allow the user to interact with the CodeBot.
-
A button press can "bounce," or detect an additional press that didn't happen. Using an extra
buttons.was_pressed()after a short delay can debounce a button press. - A number can be displayed by using LEDs.
Assessment Opportunities
- Quiz after Objective 7
- Mission 4 Lesson 2 Log
- Submit completed program CountGuests
- Submit the program with extensions
- Mission 4 Obj. 4-7 Review Kahoot!
Success Criteria
- Increment a variable to count a button press
- Use a variable to turn on a line sensor LED
- Add a beep when a button is pressed
- Debounce a button press
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.
- Look over the quiz in advance, and prepare for potential questions students may have.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- RECOMMENDATION: Use the slides instead of instructions in CodeSpace and CodeTrek. This mission is divided into 4 lessons that cover all the information, but chunked more. All goals will still be met, but students are asked to create a new program and only focus on the new material. The programs will be combined in Lesson 4. If you choose to use the instructions in CodeSpace and the CodeTrek, then don't use the slides.
- On Objective 5, students test the program by pressing the button and lighting up line sensor LEDs. They may find that a single press lights up more than one LED. I recommend bringing this up. Then see if the same thing happens for Obj. 6. This action is called "bouncing." Students learn about and fix this in Obj. 7.
-
The quiz after Obj. 7 includes a question that may be difficult. The third question has a while loop with the condition
i < 3. In this problem, theivariable is incremented outside the loop. It never changes, so the loop becomes infinite.
Lesson Outline
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 4 Lesson 1. Students can share their answers, or compare with each other.
- Question: What line of code increments a counter?
- Question: How can you avoid a ValueError?
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.
i < 3 as the condition but i is incremented outside the loop - making it infinite.🗝️ Optional: Mission 4 Obj 4-7 Kahoot! Review. A review Kahoot! is available for these four objectives. You can do it together as a class or assign it independently. (link above)
The post-mission reflection asks students to review counting guests and debouncing button presses. You can use an extension or cross-curricular activity as a post-mission activity.
End by collecting the Mission 4 Lesson 2 Log.