MakeCode block code documentation and listed examples for the micro:bit.
MakeCode block code examples for the micro:bit.
MakeCode is a free online learn-to-code platform made by Microsoft where anyone can build games and write programs for devices like the micro:bit. Programming the Strawbees Robotics board with the micro:bit starts on the MakeCode editor . In this editor has visual drag-and-drop blocks, JavaScript, and Python.
Using the micro:bit enables interactive systems to be created. When programming, generally you fit a combination of the block categories. Inputs, outputs, and processors, also known as brains, to make your system do what you want.
Block programming is snapping drag-and-drop blocks together to create scripts. These scripts are composed to create a sequential, step-by-step set of instructions.
MakeCode blocks is the core function of programming the micro:bit. Using the programming language in the form of blocks, there is a massive library of documentation for all the blocks for your reference from Microsoft.
The best way to read code documentation is on MakeCode itself. When selecting a block from the dashboard, right-click for the Help menu. Open the window from the right of the screen to reveal the block documentation on its parameters and examples of implementation.
To use the Robotics board for the micro:bit, you will need to install the Strawbees extension in MakeCode. When in the Extensions library, search for Strawbees then click on the Robotics Inventions extension. There is a Strawbees tab in your library with blocks for programming motors and LEDs. The simulator will display 3 servo motors and 2 RGB LEDs for controlling with the Robotics board.
Listed in the following sections are the custom Strawbees MakeCode blocks outlined with parameters and examples for you try!
sb.setServoPosition(sb.servo(SBServo.ServoA), 100)
Sets the position of a servo by specifying a value ranging from 0% to 100%.
Sets the position of a servo connected to the slot A all the way to the end position 100%, wait 1 second (1000 milliseconds), then return the servo to the start position 0%.
sb.setServoPosition(sb.servo(SBServo.ServoA), 100) basic.pause(1000) sb.setServoPosition(sb.servo(SBServo.ServoA), 0)
sb.transitionServoPosition(sb.servo(SBServo.ServoA), 100, 1, sb.easing(SBEasing.Linear))
Transitions the position of a servo over a duration of time (in seconds). The “shape” of the transition is specified by choosing one of the easing functions by name.
Transitions the position of a servo connected to the slot A to the end position 100%, over 2 seconds. Then transition the servo back to the start-position 0% also over 2 seconds. When the servo moves from one position to the other, the movement will start slow and then speed up, achieved by using the quad out easing function.
sb.transitionServoPosition(sb.servo(SBServo.ServoA), 100, 2, sb.easing(SBEasing.QuadOut)) sb.transitionServoPosition(sb.servo(SBServo.ServoA), 0, 2, sb.easing(SBEasing.QuadOut))
sb.setContinuousServoSpeed(sb.servo(SBServo.ServoA), 100)
Sets the speed of a continuous servo in an arbitrary range from -100% to 100%. If the connected servo is not continuous, this will not work as expected.
Sets a continuous servo connected to the socket B to full speed in the clockwise direction 100%, wait 3 seconds (3000 milliseconds), then revert the direction to counter-clockwise, on half speed -50%.
sb.setContinuousServoSpeed(sb.servo(SBServo.ServoB), 100) basic.pause(3000) sb.setContinuousServoSpeed(sb.servo(SBServo.ServoB), -50)
sb.turnOffServo(sb.servo(SBServo.ServoA))
Turns a servo off so that no force will be applied, and it can be rotated manually. This saves battery power.
Sets the position of a servo connected to the slot A all the way to the end position 100%, wait 1 second (1000 milliseconds), then turn off the servo.
sb.setServoPosition(sb.servo(SBServo.ServoA), 100) basic.pause(1000) sb.turnOffServo(sb.servo(SBServo.ServoA))
sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 100, 100)
Sets the color of an individual RGB LED by specifying the amount of red, green and blue in the color.
Sets the RGB LED A to red, by specifying the color as percentages of red 100%, green 0%, and blue 0%.
sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 0, 0)
sb.setRgbLedColorHSB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 100, 100)
Sets the color of an individual RGB LED by specifying the amount of hue, saturation and brightness in the color. The amounts range from 0% to 100%.
Sets the RGB LED B to red, by specifying the color as percentages of hue 0%, saturation 100%, and brightness 100%.
sb.setRgbLedColorHSB(sb.rgbLed(SBRgbLed.RgbLedB), 0, 100, 100)
sb.setRgbLedColor(sb.rgbLed(SBRgbLed.RgbLedA), sb.color(SBColor.Red))
Sets the color of an individual RGB LED by specifying the color by name.
Sets RGB LEDs A and B, to yellow and green, respectively, by selecting the colors by name from a pre-defined list.
sb.setRgbLedColor(sb.rgbLed(SBRgbLed.RgbLedA), sb.color(SBColor.Yellow)) sb.setRgbLedColor(sb.rgbLed(SBRgbLed.RgbLedB), sb.color(SBColor.Green))
Listed below are professional learning articles to further your teaching.