Lift-Off with CodeX - Mission 4: Hatch Lock!

Mission 4 Lesson Plan

Hatch Lock

Students wire up the NeoPixel ring and a microswitch, then write code that simulates eight docking latches engaging, with a realistic 15% chance that any one of them fails.

⏱ 45-90 min 🎯 Grades 4-12+ 💻 CodeSpace 📱 CodeX 🔌 Peripherals Kit 🐍 Python
View Lesson Outline
📋

Overview

Is it drafty in here? Now that the crew has a way to conserve energy on the way to Mars, they need to make sure they can successfully dock with a supporting craft that was launched ahead of the mission. Eight locks have to engage before the hatch is sealed, and each one of them can fail.

Students connect the NeoPixel ring, light it up with RGB tuples, and use a microswitch to trigger a docking attempt. Because the locks only work 85% of the time, students generate a random number and compare it to a range, which makes this project a natural opening for conversations about failure rates, percentages, and probability.

🎯 Mission Goal: Students write code to simulate the successful latching of a supporting craft.

🎯

Learning Targets

  • I can connect the NeoPixel ring to the CodeX.
  • I can adjust the brightness and colors of the pixels on the NeoPixel ring.
  • I can use random values to change the colors of the LEDs on the NeoPixel ring.
  • I can return a random failure rate of 15%.
💡

Key Concepts

  • NeoPixel colors are set using tuples, a sequence of values similar to a Python list, in the form (red, green, blue).
  • Variables can be used to give your code memory, like remembering whether a button has been pressed.
  • A True/False failure rate can be calculated by generating a random number and comparing it to a selected range.

Assessment Opportunities

  • Check for Understanding in CodeSpace (2)
  • Mission 4 Assignment
  • Have students develop the calculations for different failure or success rates
  • Exit ticket - show code to generate a random number in a specific range
  • Submit and/or check the HatchLock program
  • Journal entry on their learning experience
☑️

Success Criteria

  • Use the microswitch to control the NeoPixels.
  • Use a loop to set the colors of the NeoPixels.
  • Use a random number generator to simulate the probability of hatch lock failure.
🧰

Classroom Materials

  • Laptop/computer with the Chrome browser
  • CodeX and connecting cable
  • NeoPixel ring
  • Microswitch
  • Optional: switch
NeoPixel ring peripheral for the CodeX with eight numbered RGB LEDs Microswitch peripheral board for the CodeX with the G, V, S labels Optional switch peripheral board for the CodeX with a blue push button
🌍

Real-World Applications

📺RGB pixels are used in almost every digital item students own, from phone screens to TVs to laptop displays.
🎮Video games and digital displays light up as you complete a task, the same pattern as the hatch locks engaging one at a time.
🏟️NeoPixels show up in traffic signals, stadium billboards, concert lighting, and holiday displays.
🚀

Extensions & Cross-Curricular

ChallengeInclude the disco ball with the hatch lock project.
ChallengeUse the buttons on the CodeX to control the disco ball speed, speeding it up and slowing it down.
ChallengeAdd a signal when all 8 hatch locks are successful, such as a sound, an image, or the CodeX pixels.
Lang ArtsStudents write about a personal experience where something failed.
ScienceDiscuss RGB in the context of light, and teach a lesson on the science of pixels.
MathExplore rates, like failure rates, and construct the algorithm for calculating them.
🔤

Vocabulary

RGB - Red, Green, Blue. The colors that mix together to make up a single pixel on a screen.
Pixel - Short for picture element. The tiny dots used to compose images and text on a digital screen.
Tuple - A sequence of items you can access with an index, like a list whose values don't change. A read-only version of a list.
Index - A number used to reference one of the elements in a list, tuple, or string.
🐍

New Python Code

neopixel.NeoPixel(exp.PORT0, 8)Sets up the NeoPixel ring, indicating the port and the number of LEDs.
power.enable_periph_vcc(True)Turns on extra power to the NeoPixel ring.
randint(low, high)Returns a random integer between and including low and high.
(red, green, blue)A tuple with three items, used for RGB colors.
np[pixel]Accesses a single item [pixel] in the list np.
returnReturns a value to the statement that called the function.
📐

Standards

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-16 2-AP-19

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-09 3A-AP-13 3A-AP-14 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18 3A-IC-26

CSTA Standards - Grades 11-12

3B-CS-02 3B-AP-10 3B-AP-12 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-17
📝
Preparing for the Lesson
  • Students need a computer or laptop with the Chrome web browser.
  • Make sure students can successfully log in to make.firialabs.com.
  • Set out a NeoPixel ring and a microswitch for each student or pair, plus the optional switch if you plan to use it.
  • Plug in a NeoPixel ring yourself once before class so you can show students how it seats directly on the CodeX.

🧑‍🏫
Teacher Notes
  • The NeoPixel ring can be plugged directly into the CodeX without a cable.
  • Colorblind students might struggle if they inadvertently focus on certain color combinations. The mission can be modified so they use color combinations that work for them.
  • Since the locks only work 85% of the time, students will be generating a random number between one and one hundred to mimic what happens in real life. If students are not familiar with percentages or struggle with interpreting data, you might need to have a conversation about how the code for checking the value of the random number models whether or not a hatch is locked.
  • Extensions and cross-curricular projects are included to enhance the concepts in the mission. You can use the extensions to extend students' programming experience. A remix is not explicitly planned here, but you can add one as an option to give students additional learning. A remix is planned after Mission 6.
🗺️

Lesson Outline

🗣️Warm-up / Hook

Students access prior knowledge by answering the pre-mission questions in the assignment doc.

  • Ask: "If a part works 85% of the time, and you need eight of them to work at once, how often do you think the whole thing succeeds?"
  • Ask: "Look closely at a phone or monitor screen. How do you think three colors make every picture you see?"
Teaching tip: Let students guess a number on the eight-locks question and write the guesses on the board. Most classes guess far too high. Coming back to those guesses at the end of the mission is the whole math lesson in one move.
📖Introduce the Mission

Set up the docking story and front-load the RGB tuple idea before students start typing.

  • Frame the mission: the crew has to dock with a supply craft, and eight locks have to engage for the hatch to seal.
  • Show how a color is a tuple of three numbers, (red, green, blue), and that each value controls how bright that one color is.
  • Point out the eight numbered LEDs on the NeoPixel ring, and that it plugs straight onto the CodeX with no cable.
  • Explain that power.enable_periph_vcc(True) is needed because the ring draws more power than the other peripherals.
Teaching tip: Warn students up front to keep brightness low. A NeoPixel ring at full brightness is genuinely uncomfortable to look at, and it drains power fast.
💻Coding Time

Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go.

  1. Connect the NeoPixel ring and set it up with neopixel.NeoPixel(exp.PORT0, 8).
  2. Adjust brightness, then light single pixels using RGB tuples and an index.
  3. Use a loop with randint() to set random colors across all eight pixels.
  4. Add the microswitch, and use a variable to remember whether it has been pressed.
  5. Build HatchLock, writing a function that returns True or False based on a random number, so about 15% of latch attempts fail.
  6. Complete both Checks for Understanding in CodeSpace.
Teaching tip: If a ring stays dark, check for the missing power.enable_periph_vcc(True) line first. That is the most common cause, not a broken ring.
Teaching tip: Watch for students reversing the comparison on the random number, which gives an 85% failure rate instead of 15%. Have them run it ten times and count. The bug shows itself.
🧑‍🤝‍🧑Class Debrief

Bring the class back together and connect the code to the probability behind it.

  • Ask: "How does comparing a random number to a range turn into a 15% failure rate?"
  • Ask: "What would you change in the code to make the locks fail 5% of the time instead?"
  • Ask: "Why does a tuple work well for a color, when a list would also hold three numbers?"
  • Go back to the warm-up guesses and compare them to what students actually saw happen.
Teaching tip: Use the exit ticket here, having students write code to generate a random number in a specific range. It takes two minutes and shows you who really understands the range, not just the copied line.
✏️Wrap-up & Review

Students answer the reflection question in the assignment doc, add a journal entry about their learning experience, and submit.

Use the Mission 4 Review Questions or the Mission 4 Review Kahoot! through whichever method you prefer, class discussion, Kahoot!, or an LMS quiz.

Teaching tip: Fast finishers can start the challenges, adding the disco ball or a success signal when all eight locks engage. Both build directly toward the Unit 2 remix after Mission 6.