To program your Circuit Playground Express board with MakeCode, attach your computer via a micro USB cable, you should see it appear as a an attached drive named "CPLAYBOOT".
In the MakeCode window below, click the pink download button in the lower right corner and move the downloaded .uf2 file to the "CPLAYBOOT" drive.
By default, the board will display Morse code for "SOS", but you can easily customize it with any capital letters or numbers. To do so, Modify the first block in within the "on start" block:
Simply replace "SOS" with your message - just be sure to use only capital letters:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Let's take a look at all of the MakeCode blocks and learn a bit about how they work …
This is where we define the variables we’ll be using to store values we need to access from our code.
message is the message we’ll be displaying in Morse code.
dotLength is the length of time (in seconds) one morse dot will take to display.
dotLength is also used to determine the durations of the other time variables (
spaceLength) So, if you change
dotLength, the other time variables will change in relation to it.
Alphabet is an array that contains the entire alphabet as capital letters.
Morse is an array that contains the morse codes used to represent the entire alphabet.
The functions do all the real work in our project. Let's look at each one and learn about what it does …
showDot function turns the LEDs red, waits for one
dotLength, then turns them off and waits for one
showDash function turns the LEDs red, waits for one
dashLength, then turns the LEDs off and waits for one
showSpace function turns the LEDs off, then waits for one
encode function translates the
message variable into morse code using the
Morse arrays. It takes each character from the
message, finds that character’s morse code equivalent, and adds that code to a variable named
MorseLights function takes all the dots and dashes stored in the
morseOut variable and converts them into LED flashes. One by one, it checks each character in
morseOut. If it finds a dot, it will call the
showDot function. If it finds a dash, it will call the
showDash function. And if it finds a space, it will call the
forever block runs two functions over and over in a loop. First it calls the
encode function to encode our message, then it calls
MorseLights to display our message in Morse code with the Circuit Playground’s LEDs.