Scratch3MicroBitBlocks

Scratch3MicroBitBlocks

Scratch 3.0 blocks to interact with a MicroBit peripheral.

Constructor

new Scratch3MicroBitBlocks(runtime)

Construct a set of MicroBit blocks.

Parameters:
Name Type Description
runtime Runtime

the Scratch 3.0 runtime.

Members

(static) EXTENSION_ID

(static) EXTENSION_NAME

(static) TILT_THRESHOLD

BUTTONS_MENU

GESTURES_MENU

PIN_STATE_MENU

runtime :Runtime

The Scratch 3.0 runtime.

Type:

TILT_DIRECTION_ANY_MENU

TILT_DIRECTION_MENU

Methods

(private) _getTiltAngle(direction) → {number}

Parameters:
Name Type Description
direction TiltDirection

the direction (front, back, left, right) to check.

Returns:
  • the tilt sensor's angle in the specified direction. Note that getTiltAngle(front) = -getTiltAngle(back) and getTiltAngle(left) = -getTiltAngle(right).
Type
number

(private) _isTilted(direction) → {boolean}

Test whether the tilt sensor is currently tilted.

Parameters:
Name Type Description
direction TiltDirection

the tilt direction to test (front, back, left, right, or any).

Returns:
  • true if the tilt sensor is tilted past a threshold in the specified direction.
Type
boolean

displayClear() → {Promise}

Turn all 5x5 matrix LEDs off.

Returns:
  • a Promise that resolves after a tick.
Type
Promise

displaySymbol(args) → {Promise}

Display a predefined symbol on the 5x5 LED matrix.

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • a Promise that resolves after a tick.
Type
Promise

displayText(args) → {Promise}

Display text on the 5x5 LED matrix.

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • a Promise that resolves after the text is done printing. Note the limit is 19 characters The print time is calculated by multiplying the number of horizontal pixels by the default scroll delay of 120ms. The number of horizontal pixels = 6px for each character in the string, 1px before the string, and 5px after the string.
Type
Promise

getInfo() → {object}

Returns:

metadata for this extension and its blocks.

Type
object

getTiltAngle(args) → {number}

Properties:
Name Type Description
DIRECTION TiltDirection

the direction (front, back, left, right) to check.

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • the tilt sensor's angle in the specified direction. Note that getTiltAngle(front) = -getTiltAngle(back) and getTiltAngle(left) = -getTiltAngle(right).
Type
number

isButtonPressed(args) → {boolean}

Test whether the A or B button is pressed

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • true if the button is pressed.
Type
boolean

isTilted(args) → {boolean}

Properties:
Name Type Description
DIRECTION TiltDirection

the tilt direction to test (front, back, left, right, or any).

Test whether the tilt sensor is currently tilted.

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • true if the tilt sensor is tilted past a threshold in the specified direction.
Type
boolean

whenButtonPressed(args) → {boolean}

Test whether the A or B button is pressed

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • true if the button is pressed.
Type
boolean

whenGesture(args) → {boolean}

Test whether the micro:bit is moving

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • true if the micro:bit is moving.
Type
boolean

(private) whenPinConnected(args) → {boolean}

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • the touch pin state.
Type
boolean

whenTilted(args) → {boolean}

Properties:
Name Type Description
DIRECTION TiltDirection

the tilt direction to test (front, back, left, right, or any).

Test whether the tilt sensor is currently tilted.

Parameters:
Name Type Description
args object

the block's arguments.

Returns:
  • true if the tilt sensor is tilted past a threshold in the specified direction.
Type
boolean