Teacher Resources: Python with Robots MS Mission 5-3

Mission 5-3: Fence Patrol Lesson 3 | Python with Robots MS
Mission 5-3 Lesson Plan

Fence Patrol Lesson 3: LineSense

Students will use data to count line detections and display the count in binary using the red user LEDs.

⏰ 40-45 min 🎯 Grades 6-8 💻 CodeSpace 🤖 CodeBot 🐍 Python
View Lesson Outline
📋

Overview

Mission 5-3 focuses on the third goal of the Fence Patrol mission. Students add a safety wait feature, then learn how functions can return values. They use Boolean return values to detect line crossings, increment a counter, and display the count in binary using CodeBot's 8 red user LEDs. The lesson also covers resetting a counter to avoid a runtime error.

🎯 Mission Goal: Students will write a LineSense program that counts line detections and displays the running count in binary on the user LEDs.

🎯

Learning Targets

  • I can add a "wait" feature to a program.
  • I can define a function that returns a Boolean value.
  • I can make a contact counter to show each line-detect on the user LEDs.
  • I can use a programming technique to avoid a runtime error.
💡

Key Concepts

  • Engineers build in safety features, like waiting for a button press before starting.
  • Reusing code is fundamental. This lesson uses the same or similar code from two previous programs.
  • Boolean values (and variables) can be used as a toggle, like turning on/off LEDs, and also as a detection tool.
  • Functions can return a value as well as receive one. To return a value, use the return statement. If a return statement isn't explicitly given, the function will return None.

Assessment Opportunities

Success Criteria

  • Use a while loop to wait for a button press
  • Use a return statement in a function
  • Call a function that has a return statement
  • Use a function's return Boolean value as a condition
  • Define and increment a counter variable
  • Display a number in binary using LEDs
  • Avoid a runtime error by resetting the counter variable when it reaches its maximum number
🧰

Classroom Materials

  • CodeBot
  • USB cable
  • CodeBot Test Surfaces
🌍

Real-World Applications

🏭In manufacturing, computers count parts on an assembly line for quality control and inventory.
🛒In retail, sensors count customers entering stores or track how many items remain on shelves.
🌿In agriculture, sensors monitor crops and count livestock for data-driven decision making.
🏥In healthcare, machines count blood cells and other biological data for diagnoses.
🚦In smart cities, sensors control traffic flow and monitor pedestrian activity. Many of these real-world systems use LEDs and other visual indicators - not computer screens - to display data.
🚀

Extensions & Cross-Curricular

ExtensionPlay a tone when the counter variable is incremented.
MathThis program uses a function that returns a value. Discuss what a function is in math. Four sample functions are given in the mission log. Students can also write their own and practice evaluating functions and returning the value.
MathReview binary numbers and why 255 is the maximum number for 8 LEDs. Come up with other problems and discuss how many bits or LEDs would be required to display the max. For example, how many bits are required to keep track of all student numbers, or books in a collection?
Lang ArtsSupports language arts through reading instructions, guided notes, and reflection writing.
🔤

Vocabulary

Return statement - Exits the function and sends a value back to the code where the function was called.
Runtime error - A coding error that happens when the program is actively running.
🐍

New Python Code

while True: if buttons.was_pressed(0): break (Review) Wait loop. A safety feature - the 'bot waits until BTN-0 is pressed before continuing the program.
return is_detected return got_line Function return. The value of the variable is returned to the code where the function was called.
hit = scan_lines() if detect_line() Function call. The value of the return is used in the assignment or if statement.
leds.user(line_count) Use a variable to turn on user LEDs. line_count needs to have a value from 0 to 255.
line_count = line_count + 1 if line_count == 256: line_count = 0 Reset a counter variable when it reaches its maximum number to avoid a runtime error.
📐

Standards

CSTA K-12 CS Standards

2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-17 2-AP-19