MicroBlocks:
Visual Coding for
the MakerPort
Congratulations on the first part!
You’ll recall that our “story” for the clown is that whenever the music
is playing, he is happy, but when there isn’t any music he is sad.
Here are the blocks that do that:
Let’s edit the program that you have so far to do this.
2
One of the MakerPort blocks in MicroBlocks is “loudness”, and it
gives the program a value between 0 and 1023 for how loud music,
voice or tones are at that moment. “5” is pretty quiet, so a value of 5
or less is a good indication that the music isn’t playing.
Start by dragging the “greater than” operator block into the when hat.
Then, from the MakerPort category, drag the loudness pin block to
where the (3) is, and edit (4) to be (5).
3
Use what you learned about adding the “set digital pin” block to add
that with the variable “LEDNumber” to the bottom of your script.
To add the servo block, you’ll first need to add the Servo library.
Click on Add library,
And then at the bottom of the list, you’ll see Servo. Choose that, and
then “Open”
4
You will now have added the Servo library to the categories on the
left. Click on that, and add “set servo” to the bottom of your script.
Finally, use the Variables category to fill in the Servo1 and
HappyAngle variables.
For the sad “when” script, use the “less-than or equal” block from
“Operators” so that the last script looks like this:
5
Your complete program should now look like this:
Try it Out!
As before, with the MakerPort connected to your laptop and the
MicroBlocks editor, click on the “Go” triangle to run your program.
It should now operate such that touching touchpoint 1 and waiting for
the music to start moves the face to the happy position. Releasing
the touchpoint stops the music, and the face moves to the sad
position. Touching any other touchpoint plays the music for 1 minute,
even after a touchpoint is released.
6
The MakerPort USB flash drive
Here’s something neat: you can save your programs right to the
microSD card built into the MakerPort! That way you’ll always have
your programs for it “right there”. Remember, just use the switch on
the side to change to the “files” position while connected to the
MakerPort with the USB cable. Then move it back to “code” when
you’re done.
Explore and Create!
This has been a brief introduction to MicroBlocks, and we hope
enough to open the door for you to see how easy it can be.
We can’t wait to see what you create!
* * * * * *
Important: Remember, you can always restore the original
MakerPort Startup Program by opening it from the Examples
category in the MicroBlocks Editor.
Note: The difference between the “MakerPort Startup Program
(Animatronics)”, and “MakerPort Startup Program (Basic)” is that the
Animatronics version looks for sensors such as the distance sensor,
and has built-in programs for things like the Halloween Lantern. The
Basic version is more simple and used mostly for touchpoints that
turn on/off LEDs and play an mp3 track. It also starts up faster.
7
Bonus Section: Super-Coder MicroBlocks Editor Tips
In the last part where you created this script:
You probably did it by dragging the individual blocks and variables
into place like you did for the script above it.
However, the MicroBlocks editor has some very helpful editing
features that can accomplish this much faster and easier!
Let’s try it now with the finished program open in the editor.
1. Drag the “loudness <=5” script down in the editor window to
where you have room to create a new one of the same size.
8
2. Right-click (or 2-finger tap) on the top “when loudness >5” hat
to get this menu:
And choose “duplicate all”
9
3. Move the new script to where you can easily edit it.
4. Now for the magic! Right-click (or 2-finger tap) on the “>”
symbol in the hat that you are editing.
You will get a menu of alternate operators, where you can
now choose “<=”.
10
5. Click on the green slider to edit “set digital pin” to “off” (red).
6. Right-click (or 2-finger tap) on “HappyAngle” to get the menu
that will let you change the variable to “SadAngle”.
Notice that there are also other choices that could be useful in
the future, such as finding all the other places in a program
where that variable is used.
7. Finally, select the comment from the script that you moved out
of the way, and then select and paste into the comment block
of your new script.
Here’s another useful technique: Use the cursor to draw a box
around the other duplicate script.
11
Then right-click (or 2-finger tap) on the selected total, and
choose “Delete selection”
The MicroBlocks editor has many features that make editing
programs easier. Do explore by trying the right-click (or 2-finger tap)
in many different places.
There is also a very good and complete User Guide for MicroBlocks
at:
https://wiki.microblocks.fun/en/ide
Explore, create and enjoy!
Print Edition March 3, 2025
The pdf with clickable links of this and all the other booklets is located
in the pdfs folder in the MakerPort USB flash drive, as well as links to
the original Google docs. Move the MakerPort code/files switch to the
“files” position to access them.
12