First String
Let’s start with a project that creates a string, names it s, and prints it.
Example project: first_string_intro
- Connect your micro:bit module to your computer with its USB cable.
- In a browser, go to makecode.microbit.org to open the micro:bit Makecode Editor.
- Enter and name first_string_intro.
(See Save & Edit Projects.) - Click Download.
(See Flash Projects with MakeCode Editor.)
- Open the terminal at Google Chrome Labs Serial Terminal.
(See Use the Serial Monitor.) - Verify that it displays ABC 123.
How first_string_intro Works
The block set (s) to (“ABC 123”) creates a string variable named s. The string it refers to contains the characters A B C 1 2 3. The block serial write line (s) displays the contents of the string named s.
Did You Know?
A serial write block allows you to display more than one string at a time. You will find it helpful to add a string that explains what’s about to be printed. So, instead of just serial write line (s), you could use serial write line (join (“s = “)(s)). This will become important when you make larger projects. While adjusting them to work the way you want, you can include information such as the variable name and the location within the project the serial write block is being executed. Here is an example: