Mission 5-3: Fence Patrol - PwR MS
Fence Patrol Lesson 3: LineSense
Students will use data to count line detections and display the count in binary using the red user LEDs.
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
returnstatement. If areturnstatement isn't explicitly given, the function will returnNone.
Assessment Opportunities
- Mission 5 Lesson 3 Log (digital)
- Submit completed program LineSense
- Mission 5 Obj. 6-8 Review Kahoot!
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
Digital Resources
Classroom Materials
- βΈCodeBot
- βΈUSB cable
- βΈCodeBot Test Surfaces
Real-World Applications
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
π
New Python Code
βΎ
if statement.
line_count needs to have a value from 0 to 255.
π
Standards
βΎ
CSTA K-12 CS Standards
- 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.
- 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
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)
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 5 Obj 6-8 Kahoot! Review. A review Kahoot! is available for the three objectives.
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.