Take a pair of the 60mm plastic half-spheres. Be sure to take a pair that fit together.


Since the Circuit Playground Express is about 50.6mm in diameter, it will be too loose on it's own. A simple solution is to trace a half sphere on cardboard and cut a disk to just fit inside. Cut a notch at one spot on the edge for battery wires and attach the Circuit Playground Express on one side and a battery on the other.



Once programming is done, this assembly can be placed inside one half and the sphere snapped together.

The code

First we have to decide what effect we want. Since the Circuit Playground Express has a ring of NeoPixels we can twinkle them in festive colors: red, green, and white. 

Since we're going to work with NeoPixels, we need to hook up to them. We can use the attach block for that. The Circuit Playground Express has RGB NeoPixels, not RGBW ones, so be sure the has white switch is off/red. We can place it in a when started block to have it run when the program starts running. When you've done that (as shown below), click the when started block. That will compile, download, and execute it. Now we can play with NeoPixels.

We can randomly pick a color for each NeoPixel. We can experiment and get it working with just one pixel.

Remember what was said about clicking on any value block code to have it executed. Well, the above is just that. Make sure you're connected to your board and click the top of the above code (the set block in this case). LED 1 (to the left of the USB connector should light up with one of the colors. Click repeatedly to see one of the three colors randomly appear.

We just need to do that for each pixel (1-10). We can just wrap a for block around what we have:

Click the for block and see all 10 NeoPixels get set randomly.

Now that we have all ten pixels being randomly set to one of the three colors, we can make it twinkle by doing it repeatedly with a short delay between updates:

We don't want NeoPixels flashing constantly, that would burn through battery in no time. Since the Circuit Playground Express has a built-in accelerometer and there are blocks to access it (the tiltblocks), we can trigger the twinkling effect when the ornament is jostled. Since it's hanging vertically, and the Z axis extends perpendicular to the board, it's reasonable to watch it for changes.

If we keep track of readings, we can compare the current value to the previous one. If the difference is large enough we can assume that the ornament has been jostled or tapped.

The final step is to put it all together. The constant (50 as shown) that the Z axis reading difference is compared to can be adjusted to make it more or less sensitive.

Here's the code. Unzip this and load it into MicroBlocks.

This guide was first published on Nov 25, 2018. It was last updated on Nov 25, 2018.

This page (Making an Ornament) was last updated on Nov 23, 2018.

Text editor powered by tinymce.