Microbit 航向/方位信息

« 返回首页

Microbit Magnetometer:航向/方位信息

The Microbit_Magnetometer provides the ability to configure the BBC micro:bit’s on-board magnetometer and receive one or more magnetometer samples via the appropriate methods.

More links:<ul><li>Download a sample projects for the micro:bit onboard magnetometer.</li><li>View the how to instructions for the micro:bit onboard magnetometer</li></ul>

Properties

  • BluetoothDevice – The BluetoothLE component connected to the micro:bit device (setter).

get Microbit_Magnetometer1 BluetoothDevice

set Microbit_Magnetometer1 BluetoothDevice  to

Methods

  • ReadMagnetometerBearing – Read a single bearing sample from the micro:bit. On successful read, the MagnetometerBearingReceived event will be run.

call Microbit_Magnetometer1 ReadMagnetometerBearing

  • ReadMagnetometerData – Read a single sample of magnetometer data from the micro:bit. On successful read, the MagnetometerDataReceived event will be run.

call Microbit_Magnetometer1 ReadMagnetometerData

  • ReadMagnetometerPeriod – Read the current report rate for the micro:bit magnetometer. After the period is read, it will be received by the MagnetometerPeriodReceived event.

call Microbit_Magnetometer1 ReadMagnetometerPeriod

  • RequestMagnetometerBearingUpdates – Request notifications of changes in the micro:bit’s bearing. Changes in the bearing will be reported at a rate determined by the last period value set by a call to WriteMagnetometerPeriod. Bearing data will be reported through the MagnetometerBearingReceived event.

call Microbit_Magnetometer1 RequestMagnetometerBearingUpdates

  • RequestMagnetometerDataUpdates – Request notifications of changes in the micro:bit’s magnetometer. Changes in the magnetometer will be reported at a rate determined by the last period value set by a call to WriteMagnetometerPeriod. Magnetometer data will be reported through the MagnetometerDataReceived event.

call Microbit_Magnetometer1 RequestMagnetometerDataUpdates

  • StopMagnetometerBearingUpdates – Stop receiving updates from the micro:bit’s magnetometer. Note that there may be pending messages from the device that will still be reported through the MagnetometerBearingReceived event.

call Microbit_Magnetometer1 StopMagnetometerBearingUpdates

  • StopMagnetometerDataUpdates – Stop receiving updates from the micro:bit’s magnetometer. Note that there may be pending messages from the device that will still be reported through the MagnetometerDataReceived event.

call Microbit_Magnetometer1 StopMagnetometerDataUpdates

  • WriteMagnetometerPeriod – Use the WriteMagnetometerPeriod method to change how frequently the micro:bit sends magnetometer data to App Inventor. The period is measured in milliseconds. According to the micro:bit specification, valid values are 1, 2, 5, 10, 20, 80, 160 and 640 milliseconds.

Parameters:

 * <code>Magnetometer_Period</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash;
   The new magnetometer reporting period, in milliseconds.

call Microbit_Magnetometer1 WriteMagnetometerPeriodMagnetometer_Period

Events

  • MagnetometerBearingReceived – The MagnetometerBearingReceived event is run whenever bearing samples are received from the micro:bit. This is usually a result of performing a read or request operation. The bearing value is reported as degrees relative to North.

Parameters:

 * <code>bearing_value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash;
   The bearing from North, in degrees.

when Microbit_Magnetometer1 MagnetometerBearingReceived bearing_value do

  • MagnetometerDataReceived – The MagnetometerDataReceived event is run whenever magnetometer samples are received from the micro:bit. This is usually a result of performing a read or request operation. The X, Y, and Z values are in milli-teslas, and so should be scaled by 1/1000.

Parameters:

+ <code>Magnetometer_X</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash; The X value of the magnetometer, in milliT.
+ <code>Magnetometer_Y</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash; The Y value of the magnetometer, in milliT.
+ <code>Magnetometer_Z</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash; The Z value of the magnetometer, in milliT.

when Microbit_Magnetometer1 MagnetometerDataReceived Magnetometer_X Magnetometer_Y Magnetometer_Z do

  • MagnetometerPeriodReceived – The MagnetometerPeriodReceived event is run after the micro:bit’s magnetometer period is read from the device.

Parameters:

 * <code>Magnetometer_Period</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash;
   The current reporting interval for the micro:bit's magnetometer, in milliseconds.

when Microbit_Magnetometer1 MagnetometerPeriodReceived Magnetometer_Period do

  • WroteMagnetometerPeriod – The WroteMagnetometerPeriod event is run after the micro:bit reports its period as requested by an earlier call to the ReadAccelerometerPeriod method.

Parameters:

 * <code>Magnetometer_Period</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) &mdash;
   The reporting periodf or the micro:bit's magnetometer, in milliseconds.

when Microbit_Magnetometer1 WroteMagnetometerPeriod Magnetometer_Period do