Learn
Circuit Playground: Part 1
NeoPixels: Part 2

So now we know how to turn all the lights into a single color, but how do we turn individual lights on?

Circuit Playground Express has 10 built-in NeoPixels, numbered counterclockwise:

  • cpx.pixels[0]
  • cpx.pixels[1]
  • cpx.pixels[2]
  • cpx.pixels[3]
  • . . .
  • cpx.pixels[9]

To make the NeoPixel at 0 turn on to red one time:

cpx.pixels[0] = (255, 0, 0)

To make the NeoPixel at 0 turn off:

cpx.pixels[0] = (0, 0, 0)

Note: Colors are stored as tuples by default. However, we can also use hexadecimal syntax to set values similar to colors on the web. For example, 0x100000 is equivalent to (10, 00, 00). Translated to decimal, it is (16, 0, 0).

Instructions

1.

Let’s make colors appear in a rainbow-like fashion! 🌈

Inside the while loop, set the NeoPixels into these colors below:

  • Red: (255, 0, 0)
  • Orange: (255, 85, 0)
  • Yellow: (255, 255, 0)
  • Green: (0, 255, 0)
  • Forest Green: (34, 139, 34)
  • Aqua: (0, 255, 255)
  • Blue: (0, 0, 255)
  • Dark Blue: (0, 0, 139)
  • Purple: (255, 0, 255)
  • Indigo: (75, 0, 130)
2.

Click the Download button to download the code.py file (replace the old one).

Drag and drop the downloaded file into the CIRCUITPY drive on your computer.

New colors should show up!

Note: To make the download a little easier, go to Chrome’s Preferences… > Advanced. And change the download Location to CIRCUITPY.


Press Run again when you are ready to move on.

Folder Icon

Sign up to start coding

Already have an account?