Haunted Code Chronicles - Mission 2: The Living Room

Mission 2 Lesson Plan

The Living Room

Students will learn how to read the proximity sensors and use them to detect when the television is on or off.

⏰ 45-90 minutes 🎯 Grades 5-12+ πŸ’» CodeSpace πŸ€– CodeBot 🐍 Python
View Lesson Outline
πŸ“‹

Overview

Mission 2 moves the story into the living room, where a television flickers on and off. Students munch popcorn, curve the 'bot across the room, and then meet CodeBot's proximity sensors. They print sensor readings to the console, wrap those readings in an infinite while loop, and use an if statement to react, first by lighting LEDs and then by starting and stopping the motors to cross the room while the TV is off.

🎯 Mission Goal: Students will learn how to read the proximity sensors and use them to detect when the television is on or off.

🎯

Learning Targets

  • I can move the 'bot in a curve.
  • I can identify the proximity sensors.
  • I can read the proximity sensors and print the reading on the console.
  • I can use an infinite while loop to constantly read the proximity sensors.
  • I can use an if statement to turn on and off LEDs.
  • I can use the proximity sensor readings to start and stop CodeBot.
πŸ’‘

Key Concepts

  • The REPL is also known as the console. It can be used to print data. Students will print to the console during this mission.
  • A while loop defines a block of code that is repeated while a condition is True. A while loop definition ends with a colon (:) and the block of code to be repeated must be indented.
  • An if statement has at least one branch. It uses a condition that is True or False. If the condition is True, the first branch is executed. If the condition is False, the else branch is executed.
  • An if statement definition ends with a colon (:) and the blocks of code in the branches are indented.
  • The proximity sensors return a tuple of Boolean values, which are either True or False. The tuple looks like this: (True, True) or (False, False)
βœ…

Assessment Opportunities

  • Complete the Mission 2 Activity Guide.
  • Complete and turn in program PopcornMunch after Objective 2.
  • Complete and turn in program LivingroomEscape after Objective 7.
  • Complete the Quiz after Objective 5.
  • Record the score for the mission, found in the Progress and Contests icon under Select Class.
  • Write a paragraph about their coding experience and what they learned.
β˜‘οΈ

Success Criteria

  • Munch several pieces of popcorn by touching them with CodeBot
  • Identify the proximity sensors
  • Read the proximity sensors and print the reading to REPL (the console)
  • Use an infinite while loop to read the proximity sensors
  • Use an if statement and the proximity sensor reading to turn on/off a line sensor LED
  • Guide CodeBot through the door, moving only when the television is off
🧰

Classroom Materials

  • β–ΈLaptop/computer with Chrome browser
πŸ”€

Vocabulary

β–Ύ
Proximity Sensor - Infrared sensors that enable the 'bot to detect objects based on reflected IR light.
REPL - Repeat Evaluate Print Loop, also called the console. It is a way to interactively enter commands and view output in a text format.
While Loop - A statement that tells Python to repeat a block of indented code as long as the given condition is True.
Infinite Loop - A while loop that never ends because the condition is always True.

Optional Computing Terms

Function - A named chunk of code you can run anytime just by calling its name.
Parameters - Local variables that hold information received by a function.
Arguments - Information passed to a function's parameters. Arguments can be literal or variable values.
Boolean - A data type with two possible values: True or False.
🐍

New Python Code

β–Ύ
prox.detect()Read both the proximity sensors; returns True or False for each sensor: (True, True) or (False, False)
print(light_reading)Print the light reading on the console.
if light_reading == (False, False):Compare the sensor reading to the value (False, False).
else:The False branch of an if statement.
leds.ls_num(2, True)Turn on line sensor LED 2.

Optional Python Code

def function_name():
def munch(left, right, tm):
Define a function. Function names follow the same rules as variables. The block of code inside a function must be indented.
function_name()
munch(55, 50, 4)
Call a function (no parameters). Call a function with parameters.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 3-5

1B-CS-02 1B-CS-03 1B-DA-07 1B-AP-08 1B-AP-10 1B-AP-11 1B-AP-12 1B-AP-15

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-DA-08 2-DA-09 2-AP-10 2-AP-11 2-AP-12 2-AP-13 (2-AP-14)

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-12 3A-AP-13 3A-AP-14 3A-AP-16 (3A-AP-17) (3A-AP-18)

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-06 3B-AP-10 3B-AP-11 (3B-AP-14) 3B-AP-16
πŸ“
Preparing for the Lesson
  • Go through the Mission in advance, if you can. Try at least the first couple of objectives.
  • Be familiar with opening and closing the console.

πŸ§‘β€πŸ«
Teacher Notes
  • The mission has two activity guides. They use the same questions, but the alternative guide (alt) gives added support with the questions. Use the one that best fits the needs of your students.
  • New programming concepts have very specific syntax. Students need to be really careful with how they type in the code.
  • An infinite while loop will be used starting with Objective #5. The code will not end until the STOP button is pressed.
  • The console icon in the toolbar opens the console. Once the console is open, the same icon changes and is used to close it again.
  • Whenever CodeTrek has # TODO: students should not type the comment, but they should type the actual code to accomplish the task. Sometimes CodeTrek will give additional help, and sometimes students are expected to know the code. They can look back in the Objective Panel to remember what to do.
πŸ—ΊοΈ

Lesson Outline

πŸ§‘β€πŸ€β€πŸ§‘Warm-up

The warm-up has two questions. The first one is a review of the code from Mission 1.

Before students answer the second question, go over the Mission 2 introduction. Emphasize the second paragraph about the television. You can even go to Objective 1 and close the Objective Panel to see the television and the face that appears on it. Then have them guess how CodeBot can detect if the face is showing. If they don't have previous coding or robotics experience, they probably won't know. Any guess is good, and at the end of the mission they can compare their guess with the actual sensor.

πŸ’»Mission 2 Objectives
Objective #1: Students should answer the two questions on the activity guide. Then they type the code from CodeTrek and only have to add the sleep() statement. They should not type the # TODO: comment, but instead type the actual code.
Objective #2: This objective can take a long time if students want to munch a lot of popcorn. You may want to set a time limit. The concept of a function is introduced here. If your students are beginners, you can skip this part, and students should not use CodeTrek. If students choose to use a function, they need to be very careful with the punctuation. Functions should be defined near the top of the code, just under the import statements.
Objective #3: The goal can be met with or without a function. There isn't a time limit. The 'bot will not make it through the door. The goal is met by bouncing off the door. To increase their score, students can munch popcorn before bouncing off the closed door.
Objective #4: The proximity sensors are introduced. The goal is met by clicking one of the two proximity sensors in the simulator.
Objective #5: Students learn the code for reading the proximity sensors. They print the reading to the console. Run the code for a little while to see the two readings. Pay attention to the reading when the TV is on, and when the TV is off. Students have two questions in the activity guide to answer before they run their code, and two questions to answer after they run their code.
Quiz: The quiz questions are the same questions from Objective 5.
Objective #6: The code for turning on/off the line sensor LEDs is shown. It is very similar to code for the user LEDs. CodeTrek doesn't show an import for the sleep library. If students keep the library, it is okay. Students need to be very careful with the punctuation. The if statement uses == to compare, not a single =. It must end with a colon. Because this program uses an infinite while loop, students must stop the code by clicking the STOP button.
Objective #7: There are many ways to complete the challenge. Students should be encouraged to try it their own way. If they get frustrated, you can give a hint. One way to complete the challenge is to set the motors to the same power above the while loop. Then inside the if statement, the motors can be enabled or disabled, depending on when the TV is on or off. This is just a few lines of code to add to the program.
πŸ§‘β€πŸ€β€πŸ§‘Reflection

The reflection questions can be written, shared as a class discussion, or handled through a think-pair-share activity. This is a good time to review their earlier predictions and what was learned during the mission.