Microbit 加速度传感器
The Microbit_Accelerometer
component lets users configure the BBC micro:bit’s on-board accelerometer and receive one or more accelerometer samples via the appropriate methods.
The accelerometer’s report rate, or period, determines how frequently data will be sent to App Inventor.
Properties
Methods
ReadAccelerometerData
– Read a single sample of accelerometer data from the micro:bit. On successful read, theAccelerometerDataReceived
event will be run.
ReadAccelerometerPeriod
– Read the current report rate for the micro:bit accelerometer. After the period is read, it will be received by theAccelerometerPeriodReceived
event.
RequestAccelerometerDataUpdates
– Request notifications of changes in the micro:bit’s accelerometer. Changes in the accelerometer will be reported at a rate determined by the last period value set by a call toWriteAccelerometerPeriod
. Accelerometer data will be reported through theAccelerometerDataReceived
event.
StopAccelerometerDataUpdates
– Stop receiving updates from the micro:bit’s accelerometer. Note that there may be pending messages from the device that will still be reported through theAccelerometerDataReceived
event.
WriteAccelerometerPeriod
– Use theWriteAccelerometerPeriod
method to change how frequently the micro:bit sends accelerometer 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>period</code> (_number_) — The new accelerometer reporting period, in milliseconds.
Events
AccelerometerDataReceived
– TheAccelerometerDataReceived
event is run whenever accelerometer 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 thousands of 1 Earth gravity (G=-9.8 m/s2), and so should be scaled by 1/1000.
Parameters:
+ <code>Accelerometer_X</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The X value of the accelerometer, in milliG.
+ <code>Accelerometer_Y</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The Y value of the accelerometer, in milliG.
+ <code>Accelerometer_Z</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The Z value of the accelerometer, in milliG.
AccelerometerPeriodReceived
– TheAccelerometerPeriodReceived
event is run after the micro:bit’s accelerometer period is read from the device.
Parameters:
+ <code>Accelerometer_Period</code> (_number_) — The current reporting interval for the micro:bit's accelerometer, in milliseconds.
WroteAccelerometerPeriod
– TheWroteAccelerometerPeriod
event is run after the micro:bit reports its period as requested by an earlier call to theReadAccelerometerPeriod
method.
Parameters:
+ <code>Accelerometer_Period</code> (_number_) — The reporting period for the micro:bit's accelerometer, in milliseconds.