AP CSP - Python with CodeX - RGB
RGB Colors
Students learn how the NeoPixels mix red, green, and blue light, and write functions that set the pixels to colors they choose.
Overview
This supplemental lesson continues Mission 3 and Defining Functions. Students learn about RGB colors and the tuples, or triplets, that represent them. They use a color picker to find RGB values, then add functions to their Pixels1_functions program to expand the light show with their own colors, including a random color. The lesson is completed in the CodeSpace sandbox and is not part of a mission.
🎯 Mission Goal: Students will learn about RGB lights in the NeoPixels and how to control the amount of each light.
Learning Targets
- I can identify the Red, Green and Blue values of a color using color-picking software.
- I can define a color triplet for a specific color.
- I can define a function that sets the NeoPixels to a specific color using RGB values.
- I can use random numbers to generate a random color.
Key Concepts
- NeoPixels are made up of 3 lights: red, green and blue. Each light has a brightness level that combines together to create color.
- A color can be defined by its RGB values, and those values can be used in code.
- Python includes a random library with functions that generate random numbers.
-
The
randrange()function in the random library generates a random integer between 0 and one less than the range in parentheses.
Assessment Opportunities
- RGB Colors Activity Guide
-
Pixels1_RGBprogram
Success Criteria
- Use RGB triplets to control LEDs
- Use random integers in a program
- Correctly define a function
- Understand how and when to call a function
- Define and call one or more functions in a program
Digital Resources
- ▸RGB Colors slides
- ▸RGB Colors Activity Guide
- ▸HTML Color Codes color picker
- ▸Pixels1_RGB.txt code solution
Classroom Materials
- ▸CodeX (one per student or pair)
- ▸USB-C cable
- ▸Computer with internet access for CodeSpace and the color picker website
Real-World Applications
Extensions & Cross-Curricular
BLACK), then call it at the end of the main program.
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
AP CSP Framework - Learning Objectives
AP CSP Framework - Computational Thinking Practices
- The Activity Guide is best distributed and completed digitally, but it can also be printed. Prepare it to give through your LMS.
- Students need software to pick a color and see its RGB values. HTML Color Codes is recommended, but any website that lets students pick a color and see the RGB values will work.
-
Decide whether students will modify their own
Pixels1_functionscode or start from the solution code for Pixels1_functions (from Defining Functions). - Have the Clearing CodeX slides ready for the end of the lesson.
- If you have a word wall, or another form of vocabulary presentation, prepare the new term.
- This lesson has students modify the program they created in Defining Functions by defining more functions that use RGB triplets.
- The lesson is completed on the computer, using the CodeSpace sandbox for programming. It is not part of a mission.
- Students should use "Save As" with each program to keep the original code.
- The best experience comes from students modifying their own code. To keep every student engaged, you can give them the original code to modify if needed.
- Follow the slides for instructions and guidance. Slide 3 includes a short video on RGB colors, embedded in the slide deck. A link to the YouTube video is also in the speaker notes.
- Solution code for the final program with functions is provided. It includes a function for each challenge as an example.
- At the end of the lesson, discuss clearing the CodeX before turning it in. You can use the Clearing CodeX slides.
- You can also add vocabulary to a word wall and keep a document or chart of the Python code learned during each mission.
Lesson Outline
This outline gives the narration for one way to present the lesson.
Review the last two lessons with students: Mission 3 Pixels and Defining Functions.
Then pass out the Activity Guide to students. It is best distributed and completed digitally, but it can also be printed.
Students work in pairs or individually at their computers.
After the programming exercises, students can try more variations to the program by completing the challenges. These are optional, so if you don't have time, that is okay. If you do have time, they give students additional experience.
✅ You decide what you want students to turn in for a grade, and how they turn it in: the Activity Guide and/or the Pixels1_RGB program. You can look at the code on student computers, or have them submit code. The Activity Guide can also be turned in.
Students answer two questions in their Activity Guide. You can also have a class discussion on the questions, or have students share their answers.
- How did you use functions in this lesson?
- What did you learn about RGB colors during this lesson?
Discuss clearing the CodeX before turning it in. You can use the Clearing CodeX slides.
Formative assessment:
- Daily reflection journal
- Class discussion on what they learned about functions and RGB colors
- Activity Guide completion
- Pixels1_RGB program
- Exit ticket