The Circuit Playground Express can be programmed a number of ways: it will run Arduino code, CircuitPython, or you can program it with MakeCode.
This means you can drag and drop light animations and functionality using the Circuit Playground Express' onboard sensors without ever writing a single line of code. Just snap the blocks together and watch your lights dance.
For this project, I used the Circuit Playground's onboard light sensor to turn the lights on automatically when the room gets dark. When the room brightens back up, the lights will turn off.
The lights are running MakeCode's built-in rainbow animation. Check out this guide for more info on working with neopixel strands and building your own animations.
Go to https://makecode.adafruit.com/ and select "New Project".
Set Up the Light Strand
Let's test to see if it's working.
- Plug your Circuit Playground Express into your computer with a USB cable.
- Click the reset button.
- Green lights will appear on the Circuit Playground's face and it will appear in your list of devices, called CPLAYBOOT.
If you don't see this, try double-clicking the reset button instead of single-clicking.
Click the pink Download button on your MakeCode screen and the code you just made will download to your computer. Drag it onto the CPLAYBOOT device.
Plug the light strand into power and you will see a pretty rainbow animation. Hooray!
Let's make the lights turn on auto-magically when it gets dark, and off again in bright daylight. We can do this using the Circuit Playground Express' onboard light sensor and a little bit of experimentation.
From the pink Input bin, drag four blocks:
From the Neopixel bin, drag two blocks:
We want the lights to come ON when it gets dark in the room, and go OFF when it gets bright.
Place one instance of
(strip) set brightness to (0) inside each
on light () loop. Leave the
(light) one at 0, and set the
(dark) one at 150 or so, or whatever you'd like your maximum brightness to be (on a scale of 1-255, 255 being the brightest they can go).
Next, place both the
set (dark) light threshold to 0 blocks inside the
on start loop. Change
(light) on one of them, so one triggers above a certain brightness and the other triggers below a certain darkness.
Every room or environment is different, so you'll need to experiment a bit to get the thresholds right. I found that
set (bright) to 21 and
set (dark) to 32 works well in a window-lit bedroom -- when I turn on my overhead lights, the light strand goes off, and when the overhead lights go off, the light strand comes on.
Download the code and drag it to CPLAYBOOT to test and see where your light threshold needs to be. Experiment until it behaves the way you want. A bright flashlight is helpful for experimentation!
Here's the completed project that you can play with directly.