I've built some code that triggers a color-changing Photon animation when I jump or move quickly. This is fun to work with and customize to suit your movements, and you can get some great results with a little trial-and-error. Here's a link to the finished project if you want to skip ahead and work backwards.
To follow along and learn how I did it, point your browser at www.makecode.com
Select the Circuit Playground board, since that's the one we're working with today. While you're here, take a second to notice all the other development boards MakeCode will work with. So many possibilities! Select "New Project".
You'll find yourself in the MakeCode editor window. From here, you can drag and drop snippets of code from the different blocks listed in the middle, into the workspace on the right.
We'll start with the
on_start loop, which will run some code when the Circuit Playground Express first boots up. For now, drag the
forever loop down and out of the way.
Change the default
20 since we have 20 lights. Then set the brightness to whatever you'd like. This tutu is pretty diffused with all the layers of tulle and satin, so I turned my brightness all the way up to
Adding Motion Reactivity
The Circuit Playground has a 3-axis accelerometer on board. This gives us lots of different options for motion reaction. You can find them under the INPUT tab. I used the
3g input for my tutu, but you can play with all the different options and see what works with your movement.
Click the INPUT tab. Drag an instance of
We've set up our light strand, set the brightness, and made a motion trigger. Now we need to tell our lights what we want them to do when we move. I decided on a photon of colored light shooting across the tutu whenever I jump.
We'll use the
Photon functions (also under the NEOPIXEL tab, just scroll down a bit) to create some custom animations.
Photon is a very clever tool that's super hackable. I keep on discovering that I can create new fun effects whenever I play with it.
For this project, I want an animation that dramatically changes the color of the tutu whenever I jump. We'll use a variable to change the color every time the animation runs.
Move your Circuit Playground quickly -- give it a shake -- and see what happens. We set a hue of 10 (orange) so each time you shake it, an orange light appears. This isn't quite what we want -- we want the whole strip to light up. To accomplish this, we need to add another loop.
Download again and see what happens now. Looking better! We've got the whole strip lighting up whenever we shake the Circuit Playground. But it's going wicked fast, and not changing colors yet. Let's slow it down and add some color variation.
Next we'll make a variable. Variables allow us to change a number on-the-fly. We've got
photon hue set as a number right now (
10) and we can change this up or down to change the color of the lights.
If the CPLAYBOOT drive is not appearing, here are some things to try:
- Be sure you have a Circuit Playground Express. The Classic will not work with MakeCode.
- Use a different USB cable. Some cables are "charge-only" and won't pass data. Also try using a different USB port on your computer (mine is sometimes twitchy).
- With the Circuit Playground plugged into your computer, press the tiny reset button. The lights should all turn green. If they don't, try double-clicking the reset button.
If it's still not working, head over to the Intro to Circuit Playground Express guide for more suggestions.
If you can drag the code onto CPLAYBOOT but your LED strand isn't lighting up, check to be sure that your code reflects the pin you soldered to (Did you solder to A1? Does your code reflect that?). Also be sure you've soldered your connector to the IN end of the LED strand -- it won't work if you soldered to the OUT end.