This Kitronik University
Resource is a part of the BBC micro:bit partnership
and is an in depth guide into getting started with Microsoft Block Editor.
Getting Started with Microsoft Block Editor for the BBC micro:bit:
The Microsoft Block Editor is a drag and drop editor for the BBC microbit
that provides a simple introduction to programming. Blocks snap together to build programs and are grouped by the type of function they do. When a group is selected, the commands in the whole group are highlighted and can be selected. It's a great introduction to programming for those with little or no experience.
Select a block category from the list on the left hand side of the page. 2.
Select a block from the selected category and drag it to the workspace area on the right. 3.
Snap new blocks onto existing blocks in the workspace area. As the new blocks are dragged into the workspace, the editor highlights the connecting parts of each block when they are in a valid position to snap to existing blocks.
Scripts are automatically saved on your computer's hard drive when you are not logged in. You can access older scripts when you press the 'My Scripts' button in the top left corner of the editor.
If you want to switch computers or save the progress of a current script; click on the 'my scripts' button in the top left corner of the editor:
Once you have clicked on the 'my scripts' button, it will take you to a dashboard with options on what to do with the selected script. Options include saving your script for editing later, exporting the script to another computer (as a .jsz file), cloning the script (for someone else to edit), deleting your script and publishing the script to the BBC micro:bit website.
How to Delete Blocks using Microsoft Block Editor
You can delete blocks in three ways. You have to select and highlight the blocks you want to delete (the edges change colour to yellow when the blocks are selected): 1.
Press the DELETE button on your computer. 2.
Select and drag the selected blocks into the 'bin' shaped icon in the bottom right hand corner of the editor.
Select the block and right-click on the selected blocks. A drop-down list will appear and select the 'Delete Block' option.
Changing a Program Name
A program name will be randomly assigned when the editor is first loaded. To change this; simply click or touch the current name of the program at the top of the editor. You should get a cursor with a light blue surround text box. You can now type in the new name for your program. The editor should automatically save your changes when you are online. If you don't have an internet connection, press the save icon to save your changes.
Complete list of available blocks
FOREVER Block The FOREVER Block is one of the most commonly used Block commands. All of the commands that are placed in a forever loop are run in order and then over and over forever!
WHILE DO Block The WHILE DO Block will repeatedly run the commands contained within it while the test condition is true, The test condition block snaps to the right of the 'while' text. Once this condition is no longer met, the program will continue on to the commands below this block.
FOR (I) DO Block The FOR (I) DO Block repeats a code a fixed number of times. You can specify which code is repeated using the drop-down menu and add a number specifying how many times you want it to be repeated.
REPEAT DO Block The REPEAT DO Block repeats the attached commands a set number of times.
IF DO ELSE Block The IF DO ELSE Block tests the condition snapped to the right of the 'if'text. If the condition is 'true' it will execute once the blocks snapped to the right of the 'do' text. If 'false' it will execute once the blocks snapped to the right of the 'else' text. The 'cog' wheel (when clicked on) lets extra 'else if' and 'else' elements to be added to this command. This allows for different commands to be run if different test conditions are met.
BOOLEAN VALUE TRUE/FALSE BlockS The BOOLEAN VALUES TRUE/FALSE Blocks are used when there are only two opposite answers to the command. Boolean is a logic where the answer can be either yes or no or anything you specify to be the opposite of one another.
BOOLEAN BINARY OPERATORS: AND (conjunction); OR (disjunction) BlockS The BOOLEAN VALUES AND (conjunction)/OR (disjunction) Blocks are used when two blocks need to be compared. The AND block evaluates to true only if both A and B are true, the OR block evaluates to true when either A or B are true.
BOOLEAN NOT Block: The BOOLEAN NOT Block is used when you want the opposite (negation) of A.
BOOLEAN COMPARISON OPERATOR BlockS The BOOLEAN COMPARISON OPERATOR Blocks are operator blocks within Boolean logic. These include =, !=, <, >, <= and >=. A numerical value can be inserted into both sides of these blocks in order to make the function work.
NUMERIC VALUE Block The NUMERIC VALUE Block is used to enter numeric values. These are Integers (whole numbers). The value defaults to '0' but can be changed. This Block is often used in Blocks such as the Comparison Operators Block described above.
ARITHMETIC BINARY OPERATION Blocks The ARITHMETIC OPERATION Blocks are used to perform an arithmetic (maths) operations on two items. For example by adding them together. It returns the result of this operation. This Block has spaces to place the variable or values to perform the operation on. The drop down box in the centre allows the selection of the operator type (there are five you can select).
ABSOLUTE VALUE Block The ABSOLUTE VALUE Block is a block where an absolute value of a function is needed. An absolute value is the distance away from 0 (in either direction) that number is. For example 3 and -3 both have an absolute value of 3.
MAXIMUM Block The MAXIMUM Block finds the maximum of two values you insert into each side of this function.
MINIMUM Block The MINIMUM Block finds the minimum of two values you insert into each side of this function.
RANDOM VALUE Block The RANDOM VALUE Block picks a random value between two set parameters. You can set the parameter by typing a number into the right hand side of this block.
SET ITEM TO Block The SET ITEM TO Block assigns the value of the selected variable to a value. This value could be a fixed numeric value or that of another variable.
VARIABLE VALUE Block The VARIABLE VALUE Block gets the current value of a variable you choose from a drop-down menu.
CHANGE VARIABLE VALUE Block The CHANGE VARIABLE VALUE Block gets the current value of a variable you choose from a drop-down menu and enables you to change it by a number inserted into the right side of the block.
CREATE SPRITE Block The CREATE SPRITE (GAME) Block creates a LED sprite (single LED) to show at the specified coordinates in the function.
MOVE Block The MOVE (GAME) Block moves the LED sprite by a specified number of pixels (LED rows/columns).
TURN Block The TURN (GAME) Block rotates the LED sprite by a certain number of degrees.
CHANGE Block The CHANGE Block will change any of the four input readings (x, y, direction and brightness) of a variable by a specified number.
SET Block The SET Block will set any of the four input readings (x, y, direction and brightness) of a variable by a specified number.
REPORTS Block The REPORTS Block will report the x or y position of a specified variable. This can be either a LED sprite or the brightness of the LED sprite currently on the LED matrix screen.
TOUCHING Block This TOUCHING Block Block reports if the sprite is touching a specified sprite. This can be useful in games that involve or prevent contact with other LED sprites.
TOUCHING EDGE Block The TOUCHING EDGE Block reports as true if the sprite is touching an edge of the LED matrix display.
IF ON EDGE, BOUNCE Block The IF ON EDGE, BOUNCE Block will bounce the LED sprite from the edge if the LED sprite comes in contact with any of the edges of the LED display matrix.
CHANGE SCORE BY Block The CHANGE SCORE BY Block adds the score to a game by a specified amount.
SCORE Block The SCORE Block displays the current score of a game on the LED matrix display when used with the SHOW NUMBER function. It can be used to change different parameters of the game if the player reaches a certain score.
START COUNTDOWN Block The START COUNDOWN Block starts a countdown (in milliseconds) when this function is run.
GAME OVER Block The GAME OVER Block shows 'GAME OVER' scrolling over and over again until the function is interrupted. You can use this in correspondence with the 'SHOW STRING' and 'ADD TEXT' Blocks to show an opposite ‘YOU WIN’ text when the player wins/looses.
PLAY TONE Block The PLAY TONE Block plays a tone (Notes A to G) at a set frequency (Hz) through pin P0 for a fraction of a beat (in ms). This can be used with an external device such as a piezo to play musical tones.
RING TONE Block The RING TONE Block rings a tone (in Hz) for a set amount of time.
REST Block The REST Block enables the BBC micro:bit to rest for a specified amount of time (measured in ms) as a fraction of a beat (1 – 1/16 beat).
TEMPO Block This TEMPO Block sets the tempo (speed of a musical beat) of a variable measured in beats per minute (bpm).
SET TEMPO Block This SET TEMPO Block overrides the previous instructions and sets the tempo of a period of music (in bpm) with a number block.
CHANGE TEMPO Block This CHANGE TEMPO Block changes the current tempo currently running on the BBC micro:bit and changes it to the numerical value in this function.
BBC micro:bit BLOCKS
SHOW LEDs Block The SHOW LEDs Block is used to display an image on the display. If a box is tocked then the corresponding LED will be lit up.
CLEAR SCREEN Block The CLEAR SCREEN Block (BASIC) clears the screen of LEDs currently displayed on the LED display matrix.
SHOW STRING Block The SHOW STRING Block is used to show a string of characters on the LED display. Text will scroll across the display (from left to right) until all the characters have been shown.
PAUSE Block The PAUSE block pauses the programming on the BBC micro:bit for a specified amount of time before running the next set of commands. The time interval is measured in milliseconds (ms) (1000th of a second).
SHOW NUMBER Block The SHOW NUMBER block displays a number (0-9) on the LED matrix of the BBC micro:bit.
PLOT Block The PLOT Block turns on a LED on the LED screen. You can specify which LED using the x and y coordinates in each of the number blocks.
UNPLOT Block The UNPLOT Block turns a LED currently on the screen, off. This can be used in conjunction with the PLOT (LED) function.
BRIGHTNESS Block The BRIGHTNESS Block can be added to the end of a command to specify the current brightness of the LED display.
SET BRIGHTNESS TO Block The SET BRIGHTNESS TO Block sets the brightness of the LED screen. Full brightness has a value of 255, so 127 is around 50% brightness. If the brightness is more than 100%, the code automatically sets the brightness to 100%.
STOP ANIMATION Block The STOP ANIMATION Block stops the current animation that is playing on the BBC micro:bit.
PLOT BAR GRAPH Block The PLOT BAR GRAPH Block plots a bar graph on the LED display. The bar graph can be from empty (‘0’) to filling the whole LED display ('1023').
SHOW IMAGE Block The SHOW IMAGE Block (IMAGES) shows an image on the LED display matrix followed by a 400ms pause. The offset is the number for the horizontal starting point of an image: '0' to display the first image, '5' for the second image, '10' for the third frame and so on.
SCROLL IMAGE Block The SCROLL IMAGE Block scrolls the frames within an image on the LED display. To jump from one image to another, use the offset values of '5' to jump to the right and '-5' to jump to the left. The interval time (in ms) controls the speed of the scrolling. The larger the number, the slower the scroll.
CREATE IMAGE Block The CREATE IMAGE Block creates an image on the LED display when the image boxes are checked.
CREATE BIG IMAGE Block The CREATE BIG IMAGE Block creates a larger image on the LED display when the image boxes are checked.
BBC micro:bit INPUT BLOCKS
ON PIN (P0*) PRESSED DO Block Commands placed within the ON PIN (P0*) PRESSED DO Block will run when the user holds the GND pin with one hand and presses the selected pin with the other hand.
ON BUTTON (A*) PRESSED DO Block Commands placed within the ON BUTTON (A*) PRESSED DO Block will run whenever the selected button or buttons are pressed.
BUTTON IS PRESSED Block The BUTTON IS PRESSED Block gets the state of an input button. The BBC micro:bit has two input buttons: A and B.
COMPASS HEADING Block The COMPASS HEADING Block returns the current heading (in o) for the BBC micro:bit and stores it in the 'degrees' variable.
TEMPERATURE Block The TEMPERATURE Block records the ambient temperature of the surface of the BBC micro:bit using the temperature sensor inside the CPU of the BBC micro:bit. This figure won’t be as accurate if the BBC micro:bit has been running a number of calculations after a long period of time. The temperature sensor is precise but not accurate as it might return a base line temperature offset (e.g. it will return 20 degrees when the ambient temperature is actually 17 degrees.
ACCELERATION Block The ACCELERATION Block gets the acceleration value (milli g-force) of one of the three specified dimensions (X, Y and Z axis) from the built-in accelerometer.
ROTATION Block The ROTATION Block gets a rotation angle in degrees inferred from the accelerometer readings.
LIGHT LEVEL Block The LIGHT LEVEL Block detects the current light level and displays it as a number between 0 (dark) and 255 (bright).
ON (COMMAND) DO Block The ON (Command) DO Block has a drop down list of commands. ON SHAKE uses the built-in accelerometer to detect when the BBC micro:bit is shaken, if the BBC logo on the BBC micro:bit is facing up or down. ON LOGO UP registers an event handler that will execute whenever the LED screen is perpendicular to the ground and the BBC micro:bit logo is above the LED screen. ON LOG DOWN registers an event handler that will execute whenever the LED screen is perpendicular to the ground and the BBC micro:bit logo is below the LED screen. ON SCREEN UP registers an event handler that will execute whenever the LED screen is facing the ceiling/sky. ON SCREEN DOWN registers an event handler that will execute whenever the LED screen is facing the floor.
MAGNET FORCE Block The MAGNET FORCE Block gets the magnetic force (micro Teslas) from the magnetometer and returns a number in one of three specified dimensions (x, y and z).
RUNNING TIME Block The RUNNING TIME Block gets the number of milliseconds elapsed since the script began and displays it as a scrolling number on the LED matrix. 1,000 milliseconds = 1 second.
DIGITAL READ PIN (0,1) TO PIN (P0*) Block The DIGITAL READ PIN (0,1) (P0*) Block reads the digital voltage on the selected pin and returns a '0' if there is as 'low' voltage or a '1' if it is a 'high' voltage. (A 'low' voltage is anything below 0.8 Volts. A 'high' voltage is anything above 1.6 Volts).
DIGITAL WRITE (0,1) TO PIN (P0*) Block The DIGITAL WRITE (0, 1) TO PIN (P0*) Block writes either a '0' (a low voltage) or a '1' (a high voltage) to the specified pin. To change the value that is written to the pin, select the box that has a '1' in it and edit to a '1' or '0' as required.
ANALOG READ PIN (P0*) Block The ANALOG READ PIN (P0*) Block reads the analog (variable) voltage on pin P0, P1 or P2 (depending on which is selected) and returns a number between 0 and 1024 depending on the level of the voltage present on that pin.
ANALOG WRITE (1024) TO PIN (P0*) Block The ANALOG WRITE (1024) TO PIN (P0*) Block writes an analog value (variable voltage) to in P0, P1 or P2 (depending on which is selected). The voltage on that pin will be set to a level defined by the size of the number written where 0 = 0V and 1024 = 3.3V.*SELECTING THE PIN/BUTTON The 'drop down' arrow next to the default pin 'P0' or button 'A' allows the pin/button which the command write/reads to be changed.
ANALOG SET PERIOD Block The ANALOG SET PERIOD Block configures the period of the Pulse Width Modulation (PWM) on the specified analog pin (P0, P1 or P2). Before putting in this function, the pin you want to change should be set as analog.
SERVO WRITE PIN Block
The SERVO WRITE PIN Block
writes a value to the servo on to the specified pin (P0, P1, P2), controlling the shaft accordingly:
- On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation.
- On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).
SERVO SET PULSE Block The SERVO SET PULSE Block configures the pin (P0, P1 or P2) as an analog/PWM output, configures the period to be 20ms and sets the pulse width based on the value it is given.
MAP Block The MAP Block (PINS) re-maps a number from one range to another. That is, a value of from low would get mapped to to low, a value of from high to to high, values in-between to values in-between, etc. Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The math-clamp function can be used either before or after this function, if limits to the ranges are desired.
TELL CAMERA TO Block The TELL CAMERA TO Block adds an external camera capability when an external camera is attached to the BBC micro:bit. This command can be to either a smartphone's camera or an externally connected camera. The camera commands include taking a photo, start/stop video capture, toggling front/rear, launch photo/video mode and stop/video/photo mode.
RAISE ALERT TO Block The RAISE ALERT TO Block raises an alert in the BBC micro:bit and orders the BBC micro:bit to do an external action. The options in the alert include telling the BBC micro:bit to 'display toast', vibrate, play a sound or ringtone, find my phone and ring an alarm.
TELL REMOTE CONTROL TO Block The TELL REMOTE CONTROL TO Block adds a command to an external supported remote control so you can control and tell the remote control what to do when this command is triggered. The options include telling the remote control to 'play', 'pause', 'stop', 'next/previous track', forward, rewind, volume up and volume down.
ON NOTIFIED Block The ON NOTIFIED Block runs a command when BBC micro:bit receives the selected event from a connected device. The available commands are 'incoming call', 'incoming message', 'orientation landscape', 'orientation portrait', 'shaken', 'display off' and 'display on'.
SIGNAL STRENGTH Block The SIGNAL STRENGTH Block returns the signal strength reported by the paired device from 0 (no signal) to 4 (full strength).
ON SIGNAL STRENGTH CHANGED Block The ON SIGNAL STRENGTH CHANGED Block registers code to run when the signal strength of the paired device changes.
©Kitronik Ltd – You may print this page & link to it, but must not copy the page or part thereof without Kitronik's prior written consent.