Lift-Off with CodeX - Mission 4: Hatch Lock!
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.
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.
Digital Resources
Classroom Materials
- ▸Laptop/computer with the Chrome browser
- ▸CodeX and connecting cable
- ▸NeoPixel ring
- ▸Microswitch
- ▸Optional: switch
Real-World Applications
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
low and high.
[pixel] in the list np.
📐
Standards
▾
CSTA Standards - Grades 6-8
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
- 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.
- 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
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?"
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.
Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go.
-
Connect the NeoPixel ring and set it up with
neopixel.NeoPixel(exp.PORT0, 8). - Adjust brightness, then light single pixels using RGB tuples and an index.
-
Use a loop with
randint()to set random colors across all eight pixels. - Add the microswitch, and use a variable to remember whether it has been pressed.
- Build HatchLock, writing a function that returns True or False based on a random number, so about 15% of latch attempts fail.
- Complete both Checks for Understanding in CodeSpace.
power.enable_periph_vcc(True) line first. That is the most common cause, not a broken ring.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.
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.