AP CSP CodeX - Mission 12: Night Light
Mission 12: Night Light
Students read the CodeX light sensor and use it to control pixel brightness, building a smart night light.
Overview
During this mission, students build a smart night light. They read the CodeX light sensor, decide when it is dark, and convert the reading into a brightness level for the pixels. They also review the difference between analog and digital from Mission 5. After Objective 5, students define a constant and create a function with a parameter to convert the light reading into a brightness level.
🎯 Mission Goal: Students will use the light sensor to make a smart night light.
Learning Targets
- I can explain the differences between analog and digital I/O.
- I can use code to read the light sensor.
- I can convert a light sensor reading to a brightness level.
- I can use the light sensor reading to control the pixel brightness.
Key Concepts
- The photocell helps convert light level into an electrical voltage level.
- Analog means infinite variation from dark to light, cold to hot, and so on. The CodeX's analog to digital converter (ADC) gives a digital approximation of the photocell's analog reading.
-
I/O pins can be read with
read_digital()andread_analog()functions.
Assessment Opportunities
- Mission 12 Assignment
- Analog and Digital slides (Mission 5)
- NightLight program
- Mission 12 Kahoot! Review
Success Criteria
- Read data from the light sensor
- Use the data to control the pixel light
- Convert data to a brightness level
- Use the converted data to set the pixels' brightness level
- Create and call a function with a parameter
Digital Resources
- ▸Mission 12 Assignment
- ▸Mission 12 Kahoot! Review
- ▸Code Solutions and Assignment Answers - Teacher Dashboard > Educator Resources button
Classroom Materials
- ▸CodeX
- ▸USB-C cable
- ▸Computer
Real-World Applications
- Your phone has a tiny ambient light sensor near the front camera
- Automatic street lights turn on at dusk and off at sunrise
- Solar panels use light sensors to find where the sun is brightest
- Pulse oximeters (pulse detection) use optical and light sensors to check your heart rate and blood oxygen
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AP CSP Framework
- The assignment is best completed digitally. Prepare the assignment to give through your LMS.
- Have the Analog and Digital slides from Unit 1 Mission 5 ready to review after Objective 1.
- If you have a word wall, or another form of vocabulary presentation, prepare the new terms.
- Encourage the students to do as much code on their own as they can, and use CodeTrek to check their work, or as a hint when needed.
- The assignment adds an extra step to complete after Objective 5, before turning in the program.
- If you have time at the end of the lesson, use the Mission 12 Kahoot! Review.
- Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions, and additional information.
Lesson Outline
This outline gives the narration for one way to present the lesson.
In Mission 5 you learned about analog and digital sounds. What do you remember about analog and digital? Besides sounds, what else can be analog? Hold a short discussion. In today's lesson, students will use analog light and convert it to digital information, then use it in a program to control the CodeX pixels.
Randomly group students into pairs for pair programming (or they can work individually).
Students log in to one computer. Two computers can be used if they want to have the assignment open on one computer and CodeSpace on the other computer.
Students go to make.firialabs.com and should be at the beginning of Mission 12.
✅ The assignment is complete and ready to turn in.
Discussion: This project introduced students to an area with lots of potential for improving the world! Light sensors and LED lights controlled with code can reduce energy consumed and make lighting more awesome!
This code can enable and enhance many real-world applications. Have students brainstorm their own applications of using a light sensor. Here are some ideas:
- Outdoor lighting: street lights, parking lots, home lighting
- Stadium lights
- Even controlling the light color so it looks better on camera
- Indoor lighting: sensing daylight from windows and skylights is called Daylight Harvesting, and it saves energy
That is exactly what your last NightLight code was doing!
Optional. Use a formative assessment for the wrap-up.
Formative assessment:
- Daily reflection journal
- Mission 12 Kahoot! Review (in class or individual)
- Exit ticket on analog and digital devices or measurements