In all More detail and examples sections below, all code example blocks can be drag/dropped onto the scripting area of MicroBlocks IDE for immediate copy and execution.
More detail and examples | |
---|---|
Turns on or off the user LED. On the micro:bit (and boards that simulate a micro:bit display) the user LED is in the center of the first row of the display. |
|
Displays a bubble with the given value(s). | |
Graphs the given value(s) in the data graph display panel. |
More detail and examples | |
---|---|
Returns the state of button A. true = pressed, false = not pressed. |
|
Returns the state of button B. true = pressed, false = not pressed. |
|
Returns the milliseconds since the last timer reset. | |
Resets the timer to zero. (milliseconds and microseconds blocks not affected) |
|
Returns the seconds since the board was powered up or hardware reset. |
|
Returns the milliseconds since the board was powered up or hardware reset. |
|
Returns the microseconds since the board was powered up or hardware reset. |
|
Returns the type of this device. eg.: micro:bit, ESP32, or Clue. |
|
Returns if microcontroller is connected to the IDE. | |
Returns the version of the firmware on the microcontroller. | |
Returns the 3-letter BLEid of the microcontroller. | |
Returns the milliseconds since the given reference time. | |
Returns the microseconds since the given reference time. |
More detail and examples | |
---|---|
Returns the value (true or false) of the given digital pin. | |
Returns the value (0 - 1023) of the given analog pin. | |
Sets the value (true or false) of the given digital pin. | |
Sets the value (0 - 1023) of the given analog pin. | |
Returns the total number of analog pins supported by this device. | |
Returns the total number of digital pins supported by this device. |
The Comm category contains blocks that communicate with hardware devices over an Inter-Integrated Circuit (I2C, pronounced "eye squared sea"), Serial Peripheral Interface (SPI) bus, or the serial UART port. These advanced blocks are usually used by people with hardware experience to create libraries for devices such as sensors or the Hummingbird:bit robotics kit.
To use these blocks, you'll need to study the data sheet for the hardware device of interest. Many I2C and SPI devices must be configured or enabled before use. It is often helpful to find and study the source code of an existing library for the device.
The Comm category is only visible when show advanced blocks has been selected.
Advanced | More detail and examples |
---|---|
Return the value of the given register (0-255) of the given I2C device (0-127). |
|
Writes an 8-bit byte (0-255) to the given I2C device and register. |
|
Receives multiple bytes from the given I2C device. | |
Sends multiple bytes to the given I2C device. | |
Sends a byte to the SPI device. | |
Reads a byte from the SPI device while sending a zero byte and returns the received byte. |
|
Opens the Serial Port at specified baud rate. | |
Closes the Serial Port. | |
Receives multiple bytes from the Serial Port. | |
Sends multiple bytes to the Serial Port. | |
Sends multiple bytes to the Serial Port starting at a selected byte. | |
Sends a byte to the softSerial Port. |
More detail and examples | |
---|---|
Blocks under this hat block run when the board is powered up or when the green RUN icon is clicked. |
|
Blocks under this hat block run when buttons A, B, or A+B are pressed. |
|
Blocks in this C-type block run over and over, indefinitely. | |
Blocks in this C-type block run the given number of times. | |
Waits the given number of milliseconds before proceeding. | |
Blocks in this C-type block run only if the given condition is true. | |
Blocks under this hat block run when the given condition becomes true. |
|
Waits until the given condition becomes true before execution proceeds to the next block in the sequence. |
|
Stops execution of the script and returns the given value as a result. | |
Blocks under this hat block run when a message of the given name is broadcast. |
|
Broadcasts the given message. | |
This block doesn't do anything. It is used to add notes and documentation to scripts. | |
Used as parameter range control in the FOR LOOP. | |
Blocks in this C-type block run the given number of times. The given variable is set to the iteration number before each iteration. |
|
Blocks in this C-type block run until the given condition becomes true. |
|
Stops running the script in which it appears. | |
Stops all other scripts running at the time, but the script in which the block appears continues to run. |
|
Advanced | |
Waits the given number of microseconds before proceeding. | |
Reports the last message received as a result of a broadcast block. | |
Reports the values of the selected function argument. | |
Calls the named custom block (function name), opt: with a parameter list. | |
Reports the result of the call of the named custom block (opt: with a list of parameters). |
More detail and examples | |
---|---|
Plus | |
Minus | |
Multiply | |
Divide | |
Returns the remainder of dividing the first number by the second. | |
Returns the magnitude of the given number (always >= 0). | |
Returns the smaller of the values. | |
Returns the larger of the values. | |
Returns a randomly chosen number between the first and second values. |
|
Returns true if the first value is smaller than the second one. |
|
Returns true if the first value is smaller than or equal to the second one. |
|
Returns true if both values are equal. | |
Returns true if the two values are not equal. | |
Returns true if the first value is greater than or equal to the second one. |
|
Returns true if the first value is greater than the second one. |
|
Boolean Constant: true or false depending on the position of the selector. |
|
Returns the logical inverse of the given boolean (e.g. "not true" returns false) | |
Returns true only if both values are true. | |
Returns true if either or both values are true. | |
Returns true if first input is a value of the given data type. | |
Returns the input expession on the left side converted to the data type menu selection made on the right side. |
|
Advanced | |
Evaluates the condition expressed in first position and returns 2nd expression if TRUE or 3rd expression if FALSE. |
|
It takes a value expressed in the first input slot and scales it from the "from" range to the "to" range. |
|
Returns the value of the given hexadecimal string. | |
Returns the bitwise AND of two numbers. | |
Returns the bitwise OR of two numbers. | |
Returns the bitwise XOR (exclusive OR) of two numbers. | |
Returns the bitwise NOT (inverse) of the given number. | |
Returns the LEFT SHIFT of the given number by the given amount. | |
Returns the RIGHT SHIFT (arithmetic) of the given number by the given amount. |
More detail and examples | |
---|---|
[Button] Creates a global variable usable in all scripts. | |
[Button] Deletes a global variable. | |
Assigns the given value to a variable. | |
Changes the value of a variable by the given amount. | |
Advanced | |
Creates a variable local to the containing script, and initializes it to the given value. |
More detail and examples | |
---|---|
Returns the Nth item of a list, string, or byte array. | |
Returns the number of items in a list, string, or byte array. | |
Combines (concatenates) strings, lists or byte arrays and returns the result. | |
Returns a short list containing the given items. | |
Adds an item to the end of a list. | |
Replaces the Nth item of a list with the given value. Can also replace all items with a value. |
|
Deletes the Nth item of a list. The resulting list is reduced in size. Can also delete all items. |
|
Returns the location of a substring within a string or an item in a list. Returns -1 if not found. | |
Returns a copy of a list, string, or byte array containing the items in the given index range. | |
returns a list by splitting the string specified by delimiter. | |
Advanced | |
Combines the items of a list into a string, optionally separated by a delimiter. | |
Returns the numeric Unicode value of the Nth character of the given string. | |
Returns the Unicode character for the given number. | |
Returns a new list of the given length with all items set to zero. | |
Returns a new byte array of the given length with all bytes set to zero. | |
Returns a byte array of the string in the input area. | |
Returns a string indicating the number of 32-bit words of dynamic memory available. |
More detail and examples | |
---|---|
[Button] Creates a user-defined command block (function). | |
[Button] Creates a user-defined reporter block (function). |
Block categories are color coded for ease of identification. Blocks in sections marked Advanced are only visible when "show advanced blocks" has been selected.