Let's start by getting our code uploaded, so we can test the lights immediately when we connect them later on.
MakeCode is an easy way to get up and running with the Circuit Playground. No prior coding knowledge is needed, and it's an easy way to experiment and learn to think like a coder. You just drag and drop code blocks, like building with Lego. MakeCode makes coding fun!
Head over to this Intro to MakeCode guide for more info on getting started with MakeCode.
- Open the project with the button above and click the blue DOWNLOAD button near the bottom of the project.
- Plug your Circuit Playground into your computer via its USB port and click the "reset" button. All the lights will turn green and your Circuit Playground will appear as a drive on your computer called CPLAYBOOT.
- Drag the code you just download onto this drive to program the Circuit Playground -- like putting files on a USB stick. That's all you need to do.
Note: If you plug in the board and you see a drive called CIRCUITPY appear, press the reset button again (double-click) to get to CPLAYBOOT.
We'll attach a wire to pin A3 and connect it to copper tape on the outside of the torch. This copper tape will act as our "switch" using the magic of capacitive touch.
There are 3 modes: Fairy lights only, Fairy lights and Circuit Playground lights, and Off.
The torch will start up with the fairy light strand lit. Touch pin A3 and the Circuit Playground's lights come on, illuminating your torch with an orange flicker animation. Touch it once more and the torch turns off.
You can add your own modes, give yourself more speed variations, or set it to start up on your favorite mode. The possibilities are endless! Poke around and change some stuff, and if it stops working you can always come back here and start fresh. Make it yours.
Take a look at the green boxes on the left:
on start and
forever. These are found under the LOOPS tab at the left. Anything in the
on start block runs just once, when the board first powers up. Anything in the
forever loop runs over and over, forever.
On Start Block
If you add or remove modes, change
To select a different start-up mode, change
You can also change the Circuit Playground brightness by choosing a number between 0 and 255.
Here is where we set up the order of our modes, and turn the fairy light strand on and off. If you want to add more modes you can do it here by clicking the + button at the bottom. Be sure to increment the mode number in each block you make, and don't forget to change
NeoPixel Control Function
The blue box in the middle contains our LED function. This is where we're telling the Circuit Playground what we want its onboard lights to do - in this case, flicker like a fiery torch.
The first purple block refers to which NeoPixel we want to light up. There are 10 NeoPixels on the face of the Circuit Playground, so using
pick random 0 to 10 will get them all to flicker in a random pattern.
We're using the HSV method to control the lights. HSV stands for Hue, Saturation, and Value. Here's some more info about how HSV works to control lights.
We can choose any hue (color) between 0 and 255. I wanted a range of oranges and yellows so my values are between 5 and 30. If you want your torch to flicker in a different color, change the hue values around until you like what you see.
Saturation I left at 255 so the colors are vibrant and fully saturated. If you want a pastel or white light, you can pull the saturation numbers down to accomplish that.
Value equates to the brightness of the LED. I wanted them pretty bright so I chose a range of values from 225-255, 255 being maximum brightness.
Capacitive Touch Switch Control
This block is where we tell the Circuit Playground to scroll through the modes each time the pad labeled A3 is touched. When it reaches the last mode (defined by the
There are also other triggers available -- you can trigger a mode change or variation when you shake or move the Circuit Playground, or whenever a loud sound is heard, or a whole host of other options. Look under the INPUT tab to see them all.
This is an easy way to make your project react to its environment. Make the torch change color whenever you clap your hands!