To make the mask light up when you talk, you'll be programming the Circuit Playground Express using Microsoft MakeCode. It's really easy to learn and fun to play around with! You can use it online at the Adafruit MakeCode site, or offline with the Windows 10 app on your computer. If you've never used MakeCode before, there's a guide to getting started here.
First, you'll figure out how to program the ring of lights on the CPX to look like a mouth opening, closing, and smiling. Then you'll add code to trigger the lights using the sound sensor/microphone built into the board.
The instructions below show two ways to trigger the lights respond to your voice. One uses a pre-built code block called
on loud. You can check out the completed code of that version by clicking the button here.
If you need to fine-tune your code to make your talking mask work better, go on to the steps that show you how to adjust the sound sensor to respond to the volume that you set using the
sound level block. This version was adapted from the Sound Activated Shark Mask learning guide. The button below takes you to sample code using that method:
The first step is to make the lights flash in a pattern that looks like a mouth talking. To do this, imagine turning the Circuit Playground Express board simulation on the screen sideways, so that the lights go across the top and the bottom.
When all the lights are lit, the "mouth" is open.
With just the bottom row lit up, the lights form a little smile.
The pattern of lights used in the example shown here is:
- The open mouth flashes on and off twice.
- The smile flashes on for a moment, then turns off.
You'll be building this part of the code using the
show ring block from the LIGHT category of blocks in the menu column. Change the colors of the ring of lights by clicking on a color in the center of the diagram and then on the lights you want to change.
To test your program, insert the code inside the
forever block that's already in the workspace whenever you open a new project. Here's how:
Program the Open Mouth
First, drag a
Then right-click on the
The lights on the simulated board should start to flash on and off continually.
Program the "Smile"
Next, take another
Duplicate the block that turns all the lights off and put it at the end of the stack.
Add Repeats and Pauses
To create a pattern of flashes where the whole ring flashes twice, drag a
Then, to adjust the timing, go back to LOOPS and drag a
Now it's time to add the sound sensor to trigger the pattern of lights!
Follow the instructions on the MakeCode guide to download your program to your CPX board.
Then test to see whether this will work for your mask by putting the CPX board near your mouth. Say something in your normal speaking voice.
If the lights don't turn on, go on to the next section and try creating some code that lets you adjust the sound sensor.
That's it! You've set the sound sensor to trigger your code when the sound level gets to 140 or above. Again, follow the instructions on the MakeCode guide to download your program to your CPX board.
Test out this setting the same way you did before and adjust it lower or higher to work with your mask.
When everything's working, go to the last page to see how to insert the electronics into your mask.