Mission 5-3: Fence Patrol - PwR MS

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

🌍

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
πŸ“
Preparing for the Lesson
  • 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. There are a couple of tables to fill out. Prepare the assignment to give through your LMS.
  • Have the Test Surfaces paper available for each student or programming pair.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms.

πŸ§‘β€πŸ«
Teacher Notes
  • The slides should replace the instructions in CodeSpace. Code will be similar to CodeTrek, but a little different. All goals will be met.
  • This lesson uses the "wait" code segment from Mission 4 Lesson 3 RobotMoves. Students should have access to the program so they can copy and paste the code.
  • The lesson introduces returning a value from a function. Some examples are given, and students have some sample code to try in the mission log.
  • The code for resetting a count variable when it reaches its max value is reviewed from Mission 4 Lesson 1 SweepLEDs. Students need to access the code, but you can review it if you want.
πŸ—ΊοΈ

Lesson Outline

πŸ’‘Lesson Tips and Tricks
Teaching tip: You can use a variety of discussion strategies to get the most engagement from your students. For example, you can have students write their answers before asking anyone for an answer. You can use one of many think-pair-share methods.
πŸ—£οΈWarm-up / Hook

Slide 2 - Students can write in their log first and then share, or discuss first and then write in their log. The warm-up question reviews the parts of a function and the vocabulary associated with it. Students can share their answers, or compare with each other.

  • Question: Fill in the chart by identifying the parts of a function (function definition, parameter, argument and function call)
πŸ’»Mission 5 Lesson 3 Activities

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.

Teaching tip: Mission Introduction - slides 3-5. This mission is divided up into four lessons. The third lesson focuses only on the third goal.
Teaching tip: Objective #6 - slides 6-11. This objective reviews the need for safety when operating a robot. The code from Mission 4 Lesson 3 is referenced. Students can copy and paste from the previous program into their new program. When they run the code, nothing should happen until BTN-0 is pressed.
Teaching tip: Objective #7 Part 1 - slides 12-16. This is a long objective, so it is divided into two parts. Part 1 discusses adding a return in a function. A definition and examples are given. Students practice working with functions that return a value in their mission log.
Teaching tip: Objective #7 Part 1 Activity - slides 17-20. Students add a return statement to both functions. After doing this part of the code, students should NOT run the program. It is continued in Part 2, and then ready for execution.
Teaching tip: Objective #7 Part 2 Activity - slides 21-25. This part of the lesson completes Objective 7. In Part 1, the functions were modified. In Part 2, the main program is modified. After completing this activity, the program is ready for testing.
Teaching tip: Objective #8 - slides 26-29. This objective is fairly short. It fixes the runtime error by resetting the count variable when it reaches its maximum value. This was also done in Mission 4 Lesson 1 and can be referenced. At the end of this objective, students should have a working program to turn in.
Teaching tip: Extension. One suggestion is given for an extension. It is completely optional, but good for students who finish early. It adds a beep to the counter. If any extension is completed, students should do a File - Save As and give the extension program a new name. The LineSense program will be continued (and completed) in the next lesson.

πŸ—½ Optional: πŸ—οΈ Mission 5 Obj 6-8 Kahoot! Review. A review Kahoot! is available for the three objectives.

πŸ§‘β€πŸ€β€πŸ§‘Post-Mission Reflection

The post-mission reflection asks students to think about functions and returns. They are asked to review the code for functions that have a return.

You can use an extension or cross-curricular activity as a post-mission activity.

End by collecting the Mission 5 Lesson 3 Log.