MakeCode is a drag-and-drop code editor that makes it easy for anyone to make the Circuit Playground Express and Crickit do things, without having to delve too deeply into code.
I've included my completed project for folks who like to skip to the end and work backwards.
If you want to build it yourself and add your own custom options, start by going to MakeCode.com and choose the Circuit Playground Express. Then choose New Project.
Go to Advanced -> Extensions and choose the Crickit extension. It will install more blocks into your MakeCode window so you can program your Crickit.
Choose the LIGHTS block and select
set brightness. Drag it into your
forever loop, and set the brightness to whatever you want. I want my snakes to be screaming bright so I chose 255.
Then, add some color. I started by
set all pixels to green. Then I
set pixel 7 to red, since I wanted one red snake.
Find the hexidecimal code for the color you want. I have a desktop widget that lets me do this quickly, or you can search online for "hex code finder" and there are plenty of tools to help.
Back in your MakeCode project, drag an instance of
set pixel color into the
forever loop for each pixel you want to change.
When you click back over to the Blocks tab, you'll see the new colors appear on the Circuit Playground image on the left. Hooray!
Crickit has four slots for servos, but for a costume project with a portable battery, it works best with just one or two. Servos take a lot of power, and while you may be tempted to use all four, the performance of your project will definitely suffer. Two servos is enough to add lots of motion. I put two snakes on each servo and so have four moving snakes on my headdress.
Click on the Crickit block and drag two instances of
crickit set servo (1) angle to (90) onto your workspace inside the
This works, but doesn't give us the slippery slithery motion we want from our snakes. It's fast and jerky instead.. useful for cat ear motion or the like, but for snakes we want to slow it down a bit. To do this, we'll use a
for loop and some variables.
Now, we will add a
for loop. This will enable us to move the servo just a little bit, over and over, with little pauses in between each step. This will effectively slow down the servo's motion to give us a more slithery feel.
Download this and give it a try. Success! The servos move slowly from one end of their rotation to the other end. Each time the
for loop is played (180 times total) the servos will move one degree.
You can adjust the speed by changing the
pause amount. Try different numbers, or maybe try adding a random number for variable speed snakes.
Now we need to add some code so they swing back the other way in a continuous back-and-forth.
We'll use our
Click Download and load the code onto your computer then from there onto your Circuit Playground Express. Test and see if you like it!
Note: make extra sure the servos can spin unobstructed. It's easy to get them tangled up in hair, crin, and light pipe. The easier they can swivel the more successful your project will be.