Skip to the content.

The MicroCode language is defined in terms of pages, where a page has a list of rules, and each rule consists of a When section and a Do section, each with a list of programming tiles.

MicroCode supports events, conditions on the events, sequencing, loops, variables, and simple arithmetic (addition, for now) over constants and variables. See samples for a list of annotated examples.

The picture below shows a 1-page program with four rules.

Smiley Button MicroCode program

The first two rules run when A is pressed.

when button A pressed, show image smiley

when button A pressed, play happy sound

The other rules are similar but trigger for button B.

Pages and rule execution

Execution of the MicroCode program starts on page 1 page 1. All the rules on that page are active. Rules on another page only become active when the program switches to that page (via an explicit switch page switch-page command, discussed later). Any rules that might still be executing on the current page (like an animation in a loop) are terminated before the page switch takes place (you can never have rules from different pages executing at the same time).

Hot potato sample

Events and rule ordering

Events are processed by MicroCode one at a time. For example, if you push the A and B buttons at (roughly) the same time, then MicroCode will process either A before B or it will process B before A. Given an event, MicroCode processes the event by executing the rules for that event in the order they appear on the current page. For each rule, this means evaluating if the conditions on the event in the When section hold and, if so, starting the rule’s Do section.

Rule termination

Most of the commands in the Do section complete quickly, such as assigning a value to a variable; others, like the display of a sequence of images take time proportional to sequence’s length; furthermore, an animation or sound sequence can be repeated multiple times (or without bound) using a repeat tile. In the case of an animation, a currently running rule that is using the micro:bit screen will be terminated if a new rule that also uses the micro:bit screen is started.

WHEN section

The left-hand side of a rule, the When section, starts with an event tile from the following dialog, which appears when you select the leftmost empty tile of a rule:

event tiles in when section

If the when section is left empty, the rule will run once when the page is started.

Event parameters and conditions

An event tile can be followed by none, one or more parameter tiles which determines the conditions under which execution will proceed from the When section to the Do section, Every event has a default parameter, which is used when no parameter is specified. The defaults are:

The dialog below shows the parameters associated with the button press/release events.

parameters for press/release event

Conditions on event values

When an event carries a numeric value (in the case of receiving a radio message or a variable being updated), if that value is equal to the sum of the values (constants and variables) that follows, then execution will proceed to the DO section. Here are the five available (dot) values:

The timer is parameterized with various times that can also be sequenced and summed:

In the case of the timer, the sum specifies the amount of time to start the timer with.

command tiles in do section

DO section

The right-hand side of a rule, the Do section, starts with a command tile from the following list:

A command can be followed by various parameter tiles, depending on the type of command. As with events, every command has a default parameter, for the case where no parameter tile is given:

Asset editors

Two editors are provided to allow the creation of 5x5 LED images and simple melodies.

LED image editor

THe LED image editor lets you select which LEDs are on/off for a frame of an animation. You can continue to add LED images in a sequence (the editor will make a copy of the last image):

Melody editor

The melody editor lets you compose a four note sequence, where each note can be C,D,E,F, or G:

Constructing numbers

For commands that expect a numeric value (radio send radio send, in variable X set variable), a variety of tiles are available

repeat repeat (loops)

A repeat repeat tile can be added to certain commands to repeat the entire DO section. The value tiles after repeat determine the number of iterations. If no value is given, it repeats forever.

when touch logo, print happy on screen

Jacdac

MicroCode will detect connected Jacdac modules and automatically display programming tiles for them. Tiles are available for all modules in Kittenbot Jacdac Kit A, as as well as the Forward Education Climate Kit. Many of the modules in Kittenbot Jacdac Kit B also are supported.

Robot

MicroCode can be used to control a micro:bit robot (read more). Make sure to start your program by setting the same radio group as the robot.

setting radio group 3 on page start

DO section

The robot robot starts the robot motor commands. Any of those can be sequenced in the same rule.

The robot had LEDs that can be controlled as well.

Some robot have an optional robotic arm.

A rule with a sequence of motor commands

The robot will automatically slow down when it detects a line; unless you are running it in fast forward. This greatly stabilizes line following algorithms.

WHEN section

The robot distance sensor is exposed as a wall tile; and the line sensor as a line tile.

Line detection is typically done with two infrared sensors under the robot.

There are 3 cases when a line is detected:

There are 3 possible state when the line detector is not detected: