MakeCode is a web-based code editor for physical computing made by Microsoft.
More on MakeCode for Adafruit boards here.
Before we start programming, let's make sure you have the CRICKIT extension installed in MakeCode.
Detailed instructions on how to do that can be found in this guide.
Head over to https://makecode.adafruit.com/ and create a new project.
Click the button below to access the code for this project.
- In a
forever loop, we set
140then play "Deck the Halls" by calling the
deckthehalls functions. The "forever" loop means this code block loops forever regardless of other events that happen in the code!
- "Deck the Halls" can be separated into 3 parts. The song starts with part 1, then repeats, then goes to parts 2 and 3. Creating functions for these song parts then "calling" the functions later allows us to have much cleaner looking and more organized code. It also allows us to reduce the amount of code needed for the project making the program more efficient!
- When capacitive touch
input A3on the CPX is touched, we want to move the servo motor from
120 degrees, and back, 10 times fast to shake the snowman. Adding the
pausein between allows the servo to have enough time to move to each position.
Now that we have the code for the project, we need to upload it to the CPX.
Let's name our file and download it.
- Choose a name at the bottom of the page.
- Then click the pink Download button.
Note MakeCode adds a UF2 extension to the filename.
Follow the directions and connect your CPX to your computer via the USB cable. Click the CPX Reset button once to go into programming mode (all NeoPixels will turn green).
In some cases, you may need to press the reset button twice to get into programming mode.
Next, look for the UF2 file in your downloads folder and drag it onto your CPLAYBOOT drive that should have showed up in your file manager/finder when you plugged in your board and entered programming mode.
You should now see the CPLAYBOOT drive disappear, this means the code is running.
Connect CRICKIT to power with the 5V DC power cable and be sure the tiny on/off switch next to the black power input jack is on.
The code should now be running so try it out!
- When the board is powered up, "Deck the Halls" should start playing.
- When the end of the alligator clip is touched, the servo should quickly move back and forth for 1 - 2 seconds.
If you are having issues getting things to work check out this extended guide here.