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
Methods
ReadMagnetometerBearing
– Read a single bearing sample from the micro:bit. On successful read, theMagnetometerBearingReceived
event will be run.
ReadMagnetometerData
– Read a single sample of magnetometer data from the micro:bit. On successful read, theMagnetometerDataReceived
event will be run.
ReadMagnetometerPeriod
– Read the current report rate for the micro:bit magnetometer. After the period is read, it will be received by theMagnetometerPeriodReceived
event.
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 toWriteMagnetometerPeriod
. Bearing data will be reported through theMagnetometerBearingReceived
event.
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 toWriteMagnetometerPeriod
. Magnetometer data will be reported through theMagnetometerDataReceived
event.
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 theMagnetometerBearingReceived
event.
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 theMagnetometerDataReceived
event.
WriteMagnetometerPeriod
– Use theWriteMagnetometerPeriod
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>) —
The new magnetometer reporting period, in milliseconds.
Events
MagnetometerBearingReceived
– TheMagnetometerBearingReceived
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>) —
The bearing from North, in degrees.
MagnetometerDataReceived
– TheMagnetometerDataReceived
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>) — 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>) — 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>) — The Z value of the magnetometer, in milliT.
MagnetometerPeriodReceived
– TheMagnetometerPeriodReceived
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>) —
The current reporting interval for the micro:bit's magnetometer, in milliseconds.
WroteMagnetometerPeriod
– TheWroteMagnetometerPeriod
event is run after the micro:bit reports its period as requested by an earlier call to theReadAccelerometerPeriod
method.
Parameters:
* <code>Magnetometer_Period</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
The reporting periodf or the micro:bit's magnetometer, in milliseconds.