Requires: Accelerometer Service.
Requires: Button Service.
Requires: Magnetometer Service.
Requires: Temperature Service.
Requires: Event Service. The accelerometer hardware must also be active (automatic if the Accelerometer Service is present).
Requires: Event Service.
Requires: Event Service. V2 only.
Requires: Event Service. Receives raw micro:bit message bus events
registered via subscribeToEvent. Higher-level events supported
by the event service, like gesturechanged and button actions, are not
included here unless you subscribe to them using subscribeToEvent.
Checks if this connection type is currently available.
Use this for pre-flight UX decisions (e.g., showing "enable Bluetooth" dialog). Note: Even if this returns "available", connect() can still fail.
A promise resolving to the current availability status.
Clear device to enable chooseDevice.
Connects to a currently paired device or requests pairing.
Optionaloptions: ConnectOptionsOptional connection options including progress callback and abort signal.
Disconnect from the device.
Removes all listeners.
Flash the micro:bit.
Not all connection types support flashing. For example, radio bridge connections do not support flashing, and Bluetooth connections only support flashing on native platforms (not Web).
Post-flash connection state differs by transport:
USB: The connection remains in ConnectionStatus.Connected state. USB connects to the micro:bit's interface chip (running DAPLink firmware), which is not affected by flashing the application processor, so the connection persists and serial communication is automatically reinitialised.
Bluetooth: The connection is always left in ConnectionStatus.Disconnected state. Bluetooth connects to the application processor directly, which reboots after flashing, so the connection is necessarily lost. Callers must call connect again after flashing.
The data to use.
Flash options and progress callback.
Gets micro:bit accelerometer data.
Requires: Accelerometer Service.
accelerometer data.
Get the board version.
Cached after the first successful connection until clearDevice is called, so remains available after disconnection.
the board version.
Gets which pins are configured as inputs. Input pins are monitored and their values reported via notifications. All other pins are outputs (the default).
Requires: IO Pin Service.
array of pin numbers (0-18) configured as inputs.
Gets micro:bit LED matrix.
Requires: LED Service.
a boolean matrix representing the micro:bit LED display.
Gets micro:bit magnetometer data.
Requires: Magnetometer Service.
magnetometer data.
Initializes the device.
Reads current values of input pins. Unlike the pinchanged event
(which only includes pins whose values changed), this returns every
pin configured as an input, up to a firmware limit of 10 pins
(lowest-numbered first).
Requires: IO Pin Service.
array of pin/value pairs.
Sets which pins are configured as inputs. Input pins are monitored and their values reported via notifications. All other pins become outputs (the default).
Note: configuring a pin as input overrides any existing pin mode (e.g. touch sensing used by MakeCode "on pin pressed" blocks). The two cannot be used on the same pin simultaneously.
Requires: IO Pin Service.
array of pin numbers (0-18) to configure as inputs.
Sets micro:bit LED matrix.
Requires: LED Service.
an boolean matrix representing the micro:bit LED display.
Sets micro:bit name filter for device requesting.
The name of the micro:bit.
Register interest in a specific micro:bit message bus event.
Tells the micro:bit to forward matching message bus traffic over BLE.
Matching events are dispatched as microbitevent.
Use 0 as the value to match all events from a source.
For common message bus events, consider the higher-level alternatives:
gesturechanged, buttonaaction, buttonbaction, buttonabaction.
Requires: Event Service.
Event source ID.
Event value to match, or 0 for any.
Sets PWM output on a pin.
Requires: IO Pin Service.
Pin number (0-18).
PWM configuration.
Period in microseconds.
Analog value (0-1024).
Writes pin data for output pins.
Requires: IO Pin Service.
array of pin/value pairs.
A Bluetooth connection to a micro:bit device.
Events and methods rely on specific BLE services being present in the micro:bit's firmware. Which services are available depends on the firmware build for C++ and for a MakeCode program depends on the service blocks added from the Bluetooth extension.
The table below maps each event and method to the BLE service it requires. If a service is not present, the event will silently not fire (no error is raised) and methods that depend on it will throw.
Accelerometer Service
accelerometerdatachangedeventButton Service
buttonachanged,buttonbchangedeventsEvent Service
gesturechangedevent — also requires the accelerometer hardware to be active; this happens automatically if the Accelerometer Service is presentbuttonaaction,buttonbaction,buttonabactioneventslogoactionevent (V2 only)microbiteventeventIO Pin Service
pinchangedeventLED Service
Magnetometer Service
magnetometerdatachangedeventTemperature Service
temperaturechangedeventUART Service
uartdataevent