AP CSP - Python with CodeX - Mission 3

Mission 3 Lesson Plan

Mission 3: Light Show

Students program the four pixel LEDs on the CodeX, use variables, and add the sleep() function to create a light show.

⏰ 45 min 🎯 Grades 9-12 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

This mission introduces the CodeX pixel LEDs, variables, and the sleep function. Students control the four pixel LEDs on the CodeX. They use a variable for the amount of delay in the sleep function to create a light show.

🎯 Mission Goal: Students will turn on and off the four RGB LEDs (NeoPixels) on the CodeX.

🎯

Learning Targets

  • I can assign data to a variable.
  • I can use variables to make code more efficient.
  • I can set the pixels using built-in colors.
💡

Key Concepts

  • The CodeX has four NeoPixels that can turn on any color represented by RGB.
  • The NeoPixels are numbered 0, 1, 2 and 3.
  • When setting a pixel, the pixel number, color and optional brightness need to be given.
  • A variable can be defined and used in code.
✅

Assessment Opportunities

☑️

Success Criteria

  • Define RGB, literal, and variable
  • Define and use a variable used in sleep()
  • Define and use a variable for color that is changed and used multiple times
  • Debug any errors in the code and keep a debugging table
  • Write a program, run it, and save it to the CodeX
🧰

Classroom Materials

  • ▸CodeX (one per student or pair)
  • ▸USB-C cable
  • ▸Computer
🌍

Real-World Applications

The skills used in this project are used by professional software developers to build:

🚦Traffic lights
🏟️Sports event scoreboards
🎮Games, and more
🗣️Discuss the use of lights and controlling them in various aspects of daily life.
🚀

Extensions & Cross-Curricular

ExtensionHave the CodeX put on a light show, like fireworks.
🔤

Vocabulary

▾
RGB - Red, Green, Blue; the colors that make up a single pixel on the screen.
Sequential - Executing code line by line, one after another, in order.
Literal - A specific value, like 1 or "hello".
Variable - A name you assign to some data that you use in code instead of the literal, or actual values.
Assign - Bind a name to a value; give a variable a value.
🐍

New Python Code

▾
pixels.set(0, GREEN)Turn on ONE pixel (pixels are numbered 0, 1, 2, 3)
from time import sleep
from time import *
Import time to use the sleep() function. Either import statement will work.
sleep(1)Pause the code for 1 second. The argument can be any decimal number, and it represents the number of seconds to pause.
delay = 1
color = RED
Define a variable and assign it a value.
sleep(delay)Use a variable as the argument for the sleep() function.
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03 3A-AP-13

CSTA Standards - Grades 11-12

3B-AP-16 3B-AP-22 3B-AP-23

AP CSP Framework

CRD-2.I - Identify the error in an algorithm or program and correct the error.
AAP-1.A - Represent a value with a variable.

AP CSP Framework - Computational Thinking Practices

3.A - Generalize data sources through variables.
4.C - Identify and correct errors in algorithms and programs, including error discovery through testing.
📝
Preparing for the Lesson
  • The assignment is best completed digitally. Prepare the assignment to give through your LMS.

🧑‍🏫
Teacher Notes
  • Start the lesson by going over the CodeX Mission Reminders slides.
  • At the end of the lesson, discuss clearing the CodeX before turning it in. You can use the Clearing CodeX slides.
  • Here is a list of all the built-in colors:
  • BLACK
  • BROWN
  • RED
  • ORANGE
  • YELLOW
  • GREEN
  • BLUE
  • PURPLE
  • GRAY
  • WHITE
  • CYAN
  • MAGENTA
  • PINK
  • LIGHT_GRAY
  • DARK_GREEN
  • DARK_BLUE
  • Instructions for using the debugger are included in this mission, in Objectives 5 and 6.
  • Another suggestion for assessment is for students to keep a daily journal, or use a reflection form for students to process information they learned and reflect on questions they may still have.
  • You may consider having students (or the class collectively) keep a chart of errors and the ways to fix them.
  • You can also add vocabulary to a word wall and keep a document or chart of the Python code learned during each mission.
  • Refer to the lesson plans in the Python with CodeX Mission Pack Curriculum for additional challenges, cross-curricular suggestions, and additional information.
  • The teaching guide gives the narration for one way to present the lesson.
🗺️

Lesson Outline

This outline gives the narration for one way to present the lesson.

🗣️Warm-up (5 min)

Use a discussion strategy, like journaling, working at boards, selecting random students, or a form of think-pair-share.

Talk to students about primary colors. They will probably say "red, yellow and blue." Mention that those are primary colors for paint, but for light the primary colors are red, green and blue. All color on your screen is made by mixing those three lights.

Teaching tip: Reminders for the beginning of the mission (slide deck: CodeX Mission Reminders)
  • Always start a new program by creating a new file and naming it appropriately. If you don't, you will lose all your previous work! Using descriptive file names is essential to finding the program later!
  • You are making a project, not just working random problems. Focus on the project-based objectives and avoid rushing through the material too quickly.
  • Test your understanding along the way by "coloring outside the lines". Try stuff!
  • Collect all the Tools you find! (They're indicated with a wrench icon.)
  • Read carefully. Usually the answer is right there in front of you!
💻Activity - Mission 3 (35 min)

Randomly group students into pairs for pair programming.

Students log in to one computer. Two computers can be used if they want to see instructions on one computer and work on the other computer. However, the assignment document requires snippets, so it will need to be open on the same computer as CodeSpace.

Students go to make.firialabs.com and begin Mission 3. They should have the digital assignment open.

Teaching tip - Objectives 5 & 6: These objectives introduce the debugger, and then have the students use the debugger. This can be a little confusing the first time (and even the third, fourth, etc.). You may want to demonstrate this with the students. The important thing to remember is that the code that is HIGHLIGHTED happens AFTER the next "step in". The students click debug once in Objective 5, but they have to click it AGAIN for Objective 6.
Teaching tip - Objective 7: If you are having students make a chart of their bugs and bug fixes, this is a good time to remind them to record their bugs and debugging strategies.
Teaching tip - Objective 8: Students will create a variable and use it in code. They may have trouble realizing they need to use it in four places, everywhere there is a sleep() command.
Teaching tip - Objective 9: Students will create another variable for the color and use it in code. They may have trouble realizing they need to use it after each group of pixels is set to a color. They can use CodeTrek for ideas, but their code doesn't have to match it exactly.

✅ The assignment is complete and ready to turn in. Both students should include their names on the document and submit the final program.

🧑‍🤝‍🧑Wrap-Up (10 min)

✅ Important! Show students how to "clear" their CodeX by creating a program file without code. These instructions are included in the Clearing CodeX slides.

  • Students create a new file called "Clear".
  • Students type the code to clear the display.
  • Run the code at the end of the class period to clear the code for the next person.

If this lesson is completed in one class period, the following can be used as a wrap-up. If you are on a block schedule and continuing to the next lesson, a wrap-up isn't necessary.

Formative assessment:

  • Daily reflection journal
  • Kahoot (in class or individual)
  • Exit ticket on vocabulary (RGB, literal, variable)
  • Group review on vocabulary (RGB, literal, variable)