Skip to main content

03Microsoft_MakeCode

Overview

Microsoft’s MakeCode editor is the perfect way to start programming and get creating with the BBC micro:bit. The colour-coded blocks are familiar to anyone who’s previously used Scratch, and yet powerful enough to access all the features of micro:bit.

image-20250815155142705

Send

Code with the model

Now you have a working ML model that recognises different movements correctly, you can use your model in MakeCode and run it on your micro:bit V2 away from a computer. Select the 'Edit in MakeCode' button. You'll see ML blocks that represent the actions you created in your model. You can change the action for each ML block and add your own code.

image-20250815155242419

image-20250815155323745

Note: If you want to edit your data, add more actions or retrain your model, select the back arrow to go back to micro:bit CreateAI.

image-20250815155425043

MakeCode ML blocks

micro:bit CreateAI projects can use a selection of ML blocks that work with your ML model. Find them in the 'Machine Learning' category at the top of the toolbox.

  • on ML ... start

This block runs when the ML model estimates that an action has started.

The ML model updates its estimated action several times a second, but this block only runs when the estimated action changes.

The 'unknown' option represents the case where the ML model estimates no action has a certainty above the recognition point.

image-20250815155526906

  • on ML ... stop

This block runs when the ML model estimates that the current action has stopped.

When the estimated action changes, the stop block for that action will run, followed by the start block for the next action.

You can also use the stop block that provides the action's duration. The duration is the number of milliseconds since this action became the estimated action. You can drag the duration into your code, for example to display it or update a variable to keep a running total.

image-20250815155615968

  • is ML ... detected

This block checks if an ML action is the estimated action.

This block compares the latest value of the estimated action to the action you select. Use the Boolean value to make logical decisions in your program.

Some programs will be easier to write using the 'on ML start' or 'on ML stop' blocks instead.

image-20250815155713758

  • certainty (%) ML ...

The certainty percentage for an ML action.

The ML model runs several times a second and calculates a certainty value for each action. The estimated action is the action with the highest certainty. An action cannot be the estimated action when its certainty is below the recognition point. Some programs may need to use the certainty values directly, for example to display or log them. Most programs can use the estimated action instead of certainty values.

The certainty is expressed as a number from 0 to 100, representing the ML model's certainty that this is the action being performed. The certainty for the 'unknown' action is always 0.

image-20250815155815657

Program

The Send program consists of 3 components:

  1. Radio Setup: After initialization, the micro:bit configures its radio communication group.
  2. No-Gesture State: When no trained gestures are detected, the LED matrix remains off.
  3. Gesture-Recognized State: Upon recognizing a gesture, the LED matrix displays the corresponding icon, and the designated character is transmitted via radio.

This program fulfills basic requirements for the case, while allowing developers to add visual enhancements or optimize interaction logic as needed.

image-20250815155934044

image-20250815160001812