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'm using the tilt and shake functions on the Circuit Playground Express to trigger animations. Tilt your head left and a "photon" animation runs from left to right. Tilt your head right and the same animation runs from right to left. If you shake your head (or hop up and down like a bunny) then the twinkle animation is triggered.
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".
We soldered our light strand to pin A1. Tell the code by adding an
Next go to "Variables" add a new variable called
Change the default
Go to the "Neopixel" bin (you may need to click the "Light" bin to make it appear). Drag
Go to "input" and grab the
Go back to the "Neopixel" bin and choose
You can choose from six different pre-programmed animations. I chose the Twinkle animation. You can also specify here how long you'd like the animation to run when you shake / hop. I liked 2 seconds -- experiment to find what works for you.
To make the lights turn off at the end of the specified time, place a Neopixel >
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.
Shake your Circuit Playground and see the neopixel strands twinkle!
Let's make the lights react when you tilt your head to the side. We'll use the "Photon" option for this. It's a little more complicated to use than the pre-canned animations, but you have a lot more control as well.
Photon moves a light or series of lights along the light strand from one end to the other. You can control a lot of factors like color, speed and tail length.
Drag another instance of
To start the Photon animation, drag an instance of
NOTE: there are also instances of the photon functions in the "Light" bin. These don't have a variable attached, which means these animations will run on the face of the Circuit Playground and not on your Neopixel strip. Be sure you've got the right one!
From the "Loops" bin, drag a
This will make the photon animation repeat for each neopixel you have, creating the apparent motion.
Add Neopixel >
(strip) photon forward by (1) block inside the loop block. Drag a
pause (500) ms block below it.
These blocks will control your animation speed. The first block advances the light by one pixel and the second controls how quickly this happens. I changed mine to
pause (10) ms because I want the animation to run really fast.
Get another instance of
Copy and paste the loop function too, and drag that below the new
(strip) photon forward by (1) to
(strip) photon forward by (-1). This will make the animation disappear (eraser) in the reverse direction as it was originally drawn.
Each hue on the neopixel strip is assigned a value: red is 0, yellow is around 60, and the colors cycle back around to red at 255.
We can use a variable to make the colors change periodically. If we start with red (hue 0) and add 5, we get an orangey-red. Add 5 more, and then 5 more, and the color will cycle through to orange and yellow and so on, all the way around the rainbow. MakeCode is smart enough to automatically wrap back to 0 when it reaches 255.
Let's use the
(item) variable, which is already set up for us.
Drag Neopixel >
Drag Variables >
Download the code and drag it to CPLAYBOOT to test your animations. You can download and test as many times as you want until you get it just right.
(tilt left) is working the way you want, we can copy/paste most of the blocks to add a
(tilt right) animation.
Click the on
Change the FIRST instance of
Here's the completed project that you can play with directly.