Brain DeCoded with CodeX - Mission 1, Objective 5: Plug In

Mission 1 · Objective 5 Lesson Plan

Plug In

Students connect the NeoPixel Ring to the CodeX and write a program to light up its pixels with random colors.

⏱ 20-40 min 🎯 Grades 8-12+ 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

Objective 5 is the first time students plug a peripheral into the CodeX. The NeoPixel Ring is a small circle of 8 RGB pixel LEDs, numbered 0 through 7, and it connects to one of the four black ports at the top of the CodeX, either directly or with the three connecting wires.

Once it is connected, students write a program that controls the ring. The code introduces RGB color values with the brightness capped at 20, a function definition, a for loop, and random integers from the random library. The code that controls the NeoPixel Ring is not the same as the code that controls the pixels on the CodeX itself, so that difference is worth calling out.

🎯 Project Goal: Students will write a Python program to control the NeoPixel Ring LEDs.

🎯

Learning Targets

  • I can connect the NeoPixel Ring to the CodeX.
  • I can control the pixels on the NeoPixel Ring.
  • I can generate random integers within a specified range.
💡

Key Concepts

  • The NeoPixel Ring connects to the CodeX using one of the 4 black ports at the top.
  • The NeoPixel Ring can be connected using the wires, or plugged in directly to the port.
  • The code to control the pixels on the NeoPixel Ring is different from the code to control the pixels on the CodeX.

Assessment Opportunities

  • Complete the program pixel_ring_fun.
  • Exit ticket: explain the three connecting wires, G, V and DI (or S).
  • Check for understanding: create a diagram of how to connect the NeoPixel Ring.

Success Criteria

  • CodeTrek steps completed
  • NeoPixel Ring connected to a port on the CodeX
  • Program runs correctly without errors
📂

Digital Resources

  • CodeX Peripherals Guide, wiring reference for the NeoPixel Ring and the other peripherals
  • Project the NeoPixel Ring Hints from CodeSpace on the board while students wire up
🧰

Classroom Materials

  • NeoPixel Ring, one per student or pair
  • Set of three connecting wires, if not plugging the ring in directly
  • CodeX and USB cable
  • Laptop/computer with Chrome browser
🚀

Extensions & Cross-Curricular

ExtensionStudents can define another color and program the B button to turn the pixels that color.
ExtensionChange the RGB colors defined at the top of the code to their own colors.
SciencePhysical science: have a lesson on light and its colors.
SciencePhysical science: have a lesson on electricity, discussing ground and power connections.
Lang ArtsHave students write about one of the topics covered in this objective.
🔤

Vocabulary

Peripheral:devices that interact with the CodeX, used for input and output.
NeoPixel Ring:an output peripheral that has 8 RGB pixel LEDs arranged in a circle, numbered 0-7.
🐍

New Python Code

from random import randintAccess the randint() function from the random library.
power.enable_periph_vcc(True)
np = neopixel.NeoPixel(exp.PORT0, 8)
Set up the NeoPixel Ring peripheral.
RGB_RED = (20, 0, 0)
RGB_GREEN = (0, 20, 0)
RGB_BLUE = (0, 0, 20)
Define an RGB color, limiting the brightness to 20. The first number is the amount of RED, the second the amount of GREEN, and the third the amount of BLUE.
def random_colors():Define a function, which is a block of code with a name that can be called anytime in the main program.
📐

Standards

Computer Science - Grades 9-12

9-12.AP.15
📝
Preparing for the Lesson

See the CodeX Peripherals Guide for wiring help before you hand out the rings.

  • Connect a NeoPixel Ring yourself and run pixel_ring_fun so you know what a working ring looks like.
  • Count out the rings and wire sets ahead of time, and decide whether students plug the ring in directly or use the three wires.
  • Read through the Hints in this objective. They carry most of the NeoPixel and RGB color detail you will want to review with the class.

🧑‍🏫
Teacher Notes
  • The Hints give a lot of information about the NeoPixel Ring and RGB colors. You may want to emphasize or review this information with your students.
  • The code includes functions and for loops. If your students are familiar with coding, spend some time going through the code and understanding what each line does.
  • Point out that the brightness numbers stay low. RGB values are capped at 20 in this program on purpose, the pixels are very bright at full value.
  • Extensions and cross-curricular projects are included to enhance the concepts in the objective. You can use the extensions to extend students' programming experience.
🗺️

Lesson Outline

🗣️Warm-up / Hook

Hold up a NeoPixel Ring and open with two questions.

  • Ask: "What do you think this needs from the CodeX in order to light up?"
  • Ask: "Where have you seen a ring of colored lights like this in the real world?"
Teaching tip: Steer the first answer toward power and instructions. That sets up the G, V and DI wires without you having to lecture on them.
📖Introduce the Objective

Introduce the ring as a peripheral, then show how it connects.

  • Peripheral: a device that interacts with the CodeX for input or output. The NeoPixel Ring is an output peripheral.
  • The ring: 8 RGB pixel LEDs in a circle, numbered 0 through 7.
  • Connecting: use one of the 4 black ports at the top of the CodeX. The ring plugs in directly, or connects with the three wires, G for ground, V for power, and DI (or S) for the data signal.
  • RGB colors: three numbers, red, green, and blue. Keep the brightness limited to 20.
Teaching tip: Say plainly that the NeoPixel Ring code is not the same as the CodeX pixel code from earlier objectives. Students who assume it carries over get stuck here.
💻Student Work Time

Students work through Objective 5 in CodeSpace and build pixel_ring_fun.

  1. Connect the NeoPixel Ring to a port on the CodeX, directly or with the three wires.
  2. Follow the CodeTrek steps to set up the peripheral and define the RGB colors.
  3. Write the random_colors() function and use randint() to pick pixels and colors.
  4. Run the program and confirm the pixels light up without errors.
Teaching tip: Dark ring, no error message? Check the wiring first, then check that power.enable_periph_vcc(True) is in the program. Those two catch most of the problems.
✏️Wrap-up & Review

Close with a quick check that the wiring made sense, not just the code.

  • Exit ticket: explain the three connecting wires, G, V and DI (or S).
  • Have students sketch a diagram of how to connect the NeoPixel Ring to the CodeX.
Teaching tip: Students who finish early can define a new color and program the B button to switch the ring to it, or replace the RGB values at the top of the program with colors of their own.