Haunted Code Chronicles - Mission 3: The Kitchen

Mission 3 Lesson Plan

The Kitchen

Students will learn about decimal and hexadecimal numbers and bitwise operators, and use them in code to control LEDs.

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

Overview

Mission 3 takes students into the kitchen for a crash course in how computers count. Students learn the binary and hexadecimal number systems and use them to control a whole string of LEDs with a single line of code. They work through logical operators and bitwise operators, read a line sensor, and put it all together to unhex the jack-o-lanterns and escape through the kitchen door.

🎯 Mission Goal: Students will learn about decimal and hexadecimal numbers and bitwise operators, and use them in code to control LEDs.

🎯

Learning Targets

  • I can control the user LEDs using binary numbers.
  • I can evaluate expressions with logical operators.
  • I can evaluate expressions with bitwise operators.
  • I can read a line sensor.
πŸ’‘

Key Concepts

  • The binary number system has two digits: 0 and 1. Computers use them to represent ON and OFF, and they can also represent True and False.
  • Hexadecimal numbers use base 16, and they are also used by computers to represent numbers.
  • Binary and hexadecimal numbers can be used to turn on and off a string of LEDs.
  • Logical operators allow for a combination of conditions. Logical operators are AND and OR.
  • Bitwise operators are used to combine binary or hexadecimal numbers. Bitwise operators are & (and) and | (or).
βœ…

Assessment Opportunities

  • Complete the Mission 3 Activity Guide.
  • Complete and turn in program BinaryBits after Objective 4.
  • Complete and turn in program UnhexPumpkins after Objective 5.
  • Complete and turn in program KitchenDoorDash after Objective 6.
  • Record the score for the mission, found in the class dashboard.
  • Write a paragraph about their coding experience and what they learned.
β˜‘οΈ

Success Criteria

  • Turn on and off a string of LEDs using binary (0b)
  • Evaluate an expression that has a logical operator
  • Turn on and off a string of LEDs using hexadecimal (0x)
  • Evaluate an expression that uses binary numbers and a bitwise operator
  • Evaluate an expression that uses hexadecimal numbers and a bitwise operator
  • Read a line sensor and use the value to unhex a pumpkin
🧰

Classroom Materials

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

Vocabulary

β–Ύ
Binary - Two digits, 0 and 1; used to represent OFF and ON or True / False.
Boolean - The data type for binary numbers; named after the mathematician George Boole.
Logical Operators - And and Or; enables programmers to handle multiple conditions.
Bit - A single binary digit, either 0 or 1.
Bitwise Operator - Used for individual bits: & (and) and | (or).
Hexadecimal - A number system with base 16.
Byte - A collection of 8 bits.
🐍

New Python Code

β–Ύ
leds.user(0b10000101)Uses binary to turn on LEDs 0, 2 and 7, and turn off all other LEDs.
leds.user(0x1A)Uses hexadecimal to turn on LEDs 1, 3 and 4 (1A = 0001 1010)
0b10000101 & 0b01110011
0x1A & 0x56
Bitwise AND operator
0b10000101 | 0b01110011
0x1A | 0x56
Bitwise OR operator
line_sensor = ls.read(2)Read line sensor #2.
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 3-5

1B-CS-02 1B-CS-03 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-07 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-09 3A-AP-13 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-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 using binary and hexadecimal numbers to control the user and line sensor LEDs.
  • Objective 1 gives a quick lesson on binary. Look it over to see if you need to do any additional front-loading or if the instructions are enough.

πŸ§‘β€πŸ«
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.
  • This mission introduces and uses binary and hexadecimal numbers. If you want additional practice, try the Binary Lesson.
  • Objective 5 is a difficult challenge. Read the tips and tricks for the objective below to help your students complete the challenge.
πŸ—ΊοΈ

Lesson Outline

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

The warm-up has two questions. Have students share their answers as a class discussion or think-pair-share. Go over the mission introduction to help them understand what will be expected during this mission.

πŸ’»Mission 3 Objectives
Objective #1: This objective is a short lesson on binary numbers and how they can be used to turn on user LEDs. For more information, you can have students click on "binary" in the Objective Panel to add it to their toolbox and read about binary numbers. To use binary numbers when controlling LEDs, use the prefix 0b. You can also use the same technique to turn on the line sensor LEDs. The only difference is there are five of them instead of eight. Example: leds.ls(0b00110)
Objective #2: This objective shows a truth table for the logical operators OR and AND. You may need to review the table with your students. Students will not start a new file for the program. They can delete all the practice code except the import statements and then add new code below. If a student clicks "Reset", they will get a new problem. There are many ways to meet the goal. Students can use code from Mission 1 to turn on or off each LED individually. They can use binary to turn on or off the LEDs with a single line of code. For the highest score, they need to incorporate the logical operator in the code somewhere, but it is not required. For example: answer = True or False
Objective #3: Just like Objective 2, there are many ways to meet this goal. CodeTrek shows one way, which is to solve the problem on your own, and then write code to turn on/off the LEDs. The hints show another way, with a higher score. It uses a variable for each number and then the bitwise operator. The third hint goes into some detail on how the bitwise operators work. It is optional. The bitwise operators are | (or) and & (and).
Objective #4: This challenge uses hexadecimal numbers. The Hint gives a table of hex numbers. You can use it to convert the numbers to binary and then go from there. If you don't want to do any conversion, your students can use the second Hint, similar to the Hint for Objective #3, and use the hexadecimal numbers to solve the problem and turn on/off the LEDs. This will be the most useful way to do it, since further objectives will have similar challenges. To use hexadecimal numbers when controlling LEDs, use the prefix 0x. Here is a sample code:
a = 0x26
b = 0xD5
leds.user(a | b)
Objective #5: This is one of the harder challenges in the mission pack. One difficulty is getting out from under the table. The activity guide encourages students to have a plan.
Tips for Objective #5: CodeBot can go under the chairs. This could be the easiest way to get out from under the table. You can keep all the codes as hexadecimal; there are a few instructions that mention changing the codes to binary, but that is not necessary. The code for moving CodeBot does perform differently from run to run. If it runs correctly once or twice and then doesn't, that doesn't mean you need to change the code, just keep running it and it will perform correctly again. Try using different camera angles: Universal is good for seeing the entire room, but Rotate and Chase are good for seeing what CodeBot sees. If your students are comfortable with functions, this is a good time to use them. You can define a function for moving the 'bot and another function for unhexing the pumpkin, and pass as a parameter the code above the pumpkin. If students don't want to do a function for unhexing, they can just type the three lines of code needed to unhex the pumpkin, filling in the correct code for the pumpkin. You don't have to go to all four pumpkins. Any three will do. You can even avoid the pumpkin under the table altogether if you want.
Objective #6: The objective can be completed on many different levels. For beginners, they just need to go through the door. The code can be just like the one used to get off the porch (Mission 1 Objective 13). If students take time to munch several snacks, this objective can take a lot of time for trial and error. For a higher score, do the same thing as DoorDash but use a function. For bonus scoring, travel around the kitchen munching on treats (with or without a function).
πŸ§‘β€πŸ€β€πŸ§‘Reflection

The reflection questions can be written, shared as a class discussion, or handled through a think-pair-share activity. This is an opportunity to promote a growth mindset.