Mission 3: Light the Way

Mission 3 Lesson Plan

Light the Way

Turn on CodeBot's LEDs using binary and decimal values, then use the sleep() function to animate them.

⏰ 1 hour 🎯 Grades 9-12+ 💻 CodeSpace 🤖 Virtual CodeBot 🐍 Python
View Lesson Outline
📋

Overview

In Mission 3, students move from communicating with CodeBot to controlling its onboard LEDs. They import the botcore library, add comments to their code, and turn on a single LED before using binary and decimal values to control CodeBot's user LEDs all at once. By the end, they use the sleep() function from the time library to animate LED patterns in a controlled sequence.

🎯 Mission Goal: Students learn the basics of Python.

🎯

Learning Targets

  • I can import a library.
  • I can use a predefined function from a library.
  • I can use comments to explain my code.
  • I can turn on a single user LED.
  • I can use binary to turn on multiple LEDs.
  • I can use decimal values to turn on or off LEDs.
  • I can delay program execution using the sleep() function from the time library.
💡

Key Concepts

  • Adding comments and blank lines in your code makes it easier to read.
  • Built-in functions come from libraries, like botcore or time.
  • The CodeBot has 17 LEDs, and each can be turned on or off using code.
  • Use the prefix 0b in front of a binary pattern to control LEDs.
  • Use the sleep() function to slow down the computer.

Assessment Opportunities

  • Quiz after Objective 3
  • Submit program code, or give students printed code and have them explain each line (Objectives 3, 4, and 5)
  • Short quiz or exit ticket demonstrating the binary code for turning on a specific pattern of user LEDs
  • Level-1 Mission 3 Review Kahoot!
☑️

Success Criteria

  • Create a new file for program code
  • Turn on a single user LED
  • Control all user LEDs using binary
  • Control all user LEDs using decimal
  • Use the sleep() function to animate the LEDs
  • Animate CodeBot's LEDs in a controlled sequence
🧰

Classroom Materials

  • Computer or Chromebook with internet access
🌍

Real-World Applications

🚗Cars rely on precisely timed LED patterns for turn signals, brake lights, and dashboard indicators.
🎭Stage and concert lighting rigs use the same on/off and timing logic to sync light shows with music.
🎮Video games and controllers use LED patterns to show player status, health, or notifications.
🚀

Extensions & Cross-Curricular

ExtensionBlink all the LEDs on and off in an animation pattern. Repeat the animation at least twice.
ExtensionUse only binary to animate the LEDs.
ExtensionUse only decimal numbers to animate the LEDs.
ScienceHave a lesson on LEDs and light.
MathDevelop an algorithm to decide how long to turn on or off the lights for a sequence that lasts a set amount of time.
🔤

Vocabulary

API - Application Programming Interface. Details how your program interacts with different services.
Library - A module that contains pre-built functions and code you can use after the library is imported.
Byte - 8 bits, which are binary digits.
Binary - Base 2. Digits are 0 and 1, or off and on.
Bit - A binary digit.
Comments - Code that doesn't get run; notes in the code about what you're doing.
Shift register - An electronic circuit that allows an array of output pins to be set HIGH or LOW based on a sequence of binary digits shifted into a single pin.
Animation - A sequence of changes, at a controlled speed.
Delay - Functions that slow things down, like sleep(); the module must be imported first.
🐍

New Python Code

from botcore import * Import the botcore library module to access its hardware and pre-built functions.
leds.user_num(0, True) Turn on one user LED (LED numbers 0-7, True=on, False=off).
leds.ls_num(0, True) Turn on a line sensor LED (LED numbers 0-4, True/False).
# Turn on LEDs 0, 3, 4, 7 A comment. Notes what the code below is doing without being run.
leds.user(0b11111111) leds.ls(0b11111) Turn on LEDs using binary. User LEDs have 8 bits, line sensor LEDs have 5 bits. Use the prefix 0b to indicate binary.
from time import sleep Import the sleep function from the time library module.
sleep(0.2) Delay program execution by seconds.
leds.user(0) Turn off user LEDs using decimal.
📐

Standards

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-09 3A-AP-19 3A-AP-21 3A-AP-23

CSTA Standards - Grades 11-12

3B-AP-22

Certiport IT Specialist: Python Standards

4.1

PCEP: Certified Entry-Level Python Programmer

Section 1.1 Section 1.2 Section 1.3 Section 4.2
📝
Preparing for the Lesson
  • It isn't explicitly mentioned, but students should start a new file for this program code. File names should be descriptive - if students are submitting the file, have them include their name in the filename.
  • Have the Mission 3 Assignment ready to hand out or post in your LMS, along with the Assignment Answers key for quick grading.
  • Pull up the Mission 3 Review Questions and have the Review Kahoot! link ready to launch for a class-wide review.
  • Keep the Mission 3 Final Code Solutions on hand as a reference if students get stuck or you want to compare approaches.
  • Preview binary notation (like 0b11111111) so you can explain it clearly if students ask, even though converting decimal and binary isn't a required skill.

🧑‍🏫
Teacher Notes
  • Discuss readability in code, such as using comments and adding blank lines.
  • Students don't need to know how to convert decimal and binary numbers, but it's a fun topic - you can spend extra time on binary numbers as an option.
  • Give students time to experiment with controlling the LEDs with binary and with decimal.
  • The quiz after Objective 3 checks binary LED control specifically, while Objectives 4 and 5 are better assessed by having students submit or explain their code.
  • The Mission 3 Review Kahoot! covers all of Mission 3, not just the binary objectives - use it as a cumulative wrap-up.
🗺️

Lesson Outline

🗣️Warm-up / Hook

Have students write or discuss their answers before revealing them.

  • Question: Where have you seen lights used to show information, like a status light or a warning light on a device you own?
  • Question: If you had to control 8 lights using just one number, how do you think that could work?
Teaching tip: Draw 8 boxes on the board and fill some in as "on." Ask students to describe the pattern as a string of 1s and 0s before introducing the word binary.
💻Mission 3 Activities

Students open CodeSpace, start a new file, and work through the Level-1 Mission 3 Assignment.

Teaching tip: Start by importing the botcore library (from botcore import *) and reviewing comments and blank lines for readability - remind students that a comment like # Turn on LEDs 0, 3, 4, 7 never actually runs.
Teaching tip: Turn on a single user LED with leds.user_num(0, True), and a single line sensor LED with leds.ls_num(0, True), before introducing binary control.
Teaching tip: Introduce binary with leds.user(0b11111111) and leds.ls(0b11111). Give the quiz after Objective 3, once students can turn on all the user LEDs (8 bits) and line sensor LEDs (5 bits) using binary.
Teaching tip: For Objectives 4 and 5, have students submit their program code, or hand them printed code and have them explain each line out loud - this is a good spot to check decimal LED control with leds.user(0).
Teaching tip: Wrap up by importing sleep() from the time library (from time import sleep) and having students chain LED states with sleep(0.2) between them to animate their LEDs in a controlled sequence.

If students finish early or need extra support, point them to the Level-1 Mission 3 Assignment Answers or the Final Code Solutions for reference.

🧑‍🤝‍🧑Post-Mission Reflection

Give a short quiz or exit ticket that has students demonstrate the binary code for turning on a specific pattern of user LEDs.

Have students work through the Level-1 Mission 3 Review Questions individually or in pairs to reinforce vocabulary like binary, bit, byte, and library.

Wrap up with the Level-1 Mission 3 Review Kahoot! to review all of Mission 3 before collecting finished programs.