Haunted Code Chronicles - Mission 5: The Library

Mission 5 Lesson Plan

The Library

Students will use an equation with modulo to turn on lamps in a pattern and use an accelerometer to drive up a ramp.

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

Overview

Mission 5 brings two new concepts into the library. First, students learn the different kinds of division Python offers, including integer division and modulo, and use an equation to light the library lamps in a repeating sequence. Then they meet CodeBot's accelerometer, unpack the three values it returns, and use those readings to keep the 'bot driving straight up a fallen bookshelf.

🎯 Mission Goal: Students will use an equation with modulo to turn on lamps in a pattern and use an accelerometer to drive up a ramp.

🎯

Learning Targets

  • I can label the parts of a division problem.
  • I can use modulo in an equation.
  • I can use the int() function in an equation.
  • I can read the accelerometer.
  • I can use an accelerometer reading to keep CodeBot moving up when its surroundings are turning.
πŸ’‘

Key Concepts

  • Programmers can use different types of division. In addition to float (or decimal), there is also integer division and modulo.
  • Modulo returns the remainder only of a division problem.
  • CodeBot has an accelerometer that tracks its position through gravitational acceleration in three dimensions. This allows the 'bot to detect motion and also use the values for navigation.
  • The accelerometer returns three values: x, y and z. The values are returned in a tuple, which can be unpacked for easy access.
βœ…

Assessment Opportunities

  • Complete the Mission 5 Activity Guide.
  • Complete and turn in program BookBox after Objective 1.
  • Complete and turn in program Lamplighter after Objective 4.
  • Complete and turn in program BookshelfRamp 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

  • Move the 'bot to knock a box off a book
  • Turn on a line sensor LED to turn on a lamp
  • Use a loop to light all lamps in a sequence
  • Use an equation with modulo to light all lamps in a sequence
  • Drive CodeBot straight up a fallen shelf
  • Drive CodeBot straight up a fallen shelf using an accelerometer reading
🧰

Classroom Materials

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

Vocabulary

β–Ύ
Epoch Time - The number of seconds since Jan. 1, 1970, a frame of reference computers use to count time.
Floor - Truncating a value to make it a whole number; like a quotient.
Modulo - The remainder of a division problem; uses the symbol %
Integer Division - Division that gives the quotient only; uses the symbol //
Accelerometer - A sensor that detects motion and gravitational acceleration.
🐍

New Python Code

β–Ύ
leds.ls_num(2, True)Turn on line sensor 2 LED
time()A function that returns the running count of seconds
int(3.14) = 3The int() function truncates a value to a whole number
17 % 5 = 2Modulo (remainder only)
light = int(time() * 3) % 5Equation for spectral dance, using modulo and int()
x, y, z = accel.read()Read the accelerometer and unpack its three values.
motors.run(LEFT, 20)
motors.run(RIGHT, 30)
Steer left
motors.run(LEFT, 30)
motors.run(RIGHT, 20)
Steer right
πŸ“

Standards

β–Ύ

CSTA Standards - Grades 3-5

1B-CS-02 1B-CS-03 1B-DA-07 1B-AP-09 1B-AP-10 1B-AP-15

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-DA-08 2-AP-10 2-AP-11 2-AP-12

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-12 3A-AP-13 3A-AP-14 3A-AP-16

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-06 3B-AP-10 3B-AP-16
πŸ“
Preparing for the Lesson
  • Go through the Mission in advance, if you can.
  • During the lesson, students create three different programs. Prepare all three programs, so you can be aware of potential problems and help students with solutions.

πŸ§‘β€πŸ«
Teacher Notes
  • There are two new concepts in this mission: modulo (Objectives 1-4) and using the accelerometer (Objectives 5-6).
  • If you would like to give your students more practice with types of division, you can use the Types of Division unplugged lesson.
πŸ—ΊοΈ

Lesson Outline

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

This mission uses modulo. The warm-up questions prepare students for this type of division. You can model long division for your students and do a whole class review on the terms. For more instruction, use the unplugged Types of Division lesson.

πŸ’»Mission 5 Objectives
Objective #1: No new concepts in this objective. Students move the 'bot to knock off the box. The 'bot can still drive unpredictably. If the code looks good but the goal isn't met, just try running the code again. The completion message for Objective #1 has the tool "Modulo". Students need to click on the term and read about it to answer a question for this objective.
Objective #2: This objective has three parts. Two of them are mentioned in the instructions: try each lamp individually and try all five lamps at the same time. The third part is in CodeTrek.
Objective #3: Students follow CodeTrek to complete the challenge. It is an intermediate step to understanding the next objective. You may need to remind students not to type # TODO:, but to type the actual code instead.
Objective #4: Students are given the equation for Hopper's dance. The instructions break down the equation into its parts. CodeTrek gives a lot of help. There are subtle changes in CodeTrek students may not notice. For example, the from time import statement adds time. The light variable is deleted. Make sure students are paying careful attention. The Hints go over modulo and integer division and give examples. The third Hint has the actual code for the equation. Students need to be very careful with parenthesis when typing the equation. Even one misplaced parenthesis can cause the program to fail.
Objective #5: Students follow CodeTrek to complete the challenge. It is an intermediate step to understanding the next objective. You may need to remind students not to type # TODO:, but to type the actual code instead.
Objective #6: Students will add a while True: loop to their code. All the code inside the loop must be indented! The second hint gives a lot of help with the if statement. It shows an if / else statement. If students use an if / elif / else statement they will get a higher score. A function can be used, but it doesn't affect the score.
πŸ§‘β€πŸ€β€πŸ§‘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 think about applications of the new concepts, outside of the challenge.