Microbit 加速度传感器

« 返回首页

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

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

get Microbit_Accelerometer1 BluetoothDevice

set Microbit_Accelerometer1 BluetoothDevice  to

Methods

  • ReadAccelerometerData – Read a single sample of accelerometer data from the micro:bit. On successful read, the AccelerometerDataReceived event will be run.

call Microbit_Accelerometer1 ReadAccelerometerData

  • ReadAccelerometerPeriod – Read the current report rate for the micro:bit accelerometer. After the period is read, it will be received by the AccelerometerPeriodReceived event.

call Microbit_Accelerometer1 ReadAccelerometerPeriod

  • 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 to WriteAccelerometerPeriod. Accelerometer data will be reported through the AccelerometerDataReceived event.

call Microbit_Accelerometer1 RequestAccelerometerDataUpdates

  • 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 the AccelerometerDataReceived event.

call Microbit_Accelerometer1 StopAccelerometerDataUpdates

  • WriteAccelerometerPeriod – Use the WriteAccelerometerPeriod 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_) &mdash; The new accelerometer reporting period, in milliseconds.

call Microbit_Accelerometer1 WriteAccelerometerPeriodperiod

Events

  • AccelerometerDataReceived – The AccelerometerDataReceived 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>) &mdash; 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>) &mdash; 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>) &mdash; The Z value of the accelerometer, in milliG.

when Microbit_Accelerometer1 AccelerometerDataReceived Accelerometer_X Accelerometer_Y Accelerometer_Z do

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

Parameters:

+ <code>Accelerometer_Period</code> (_number_) &mdash; The current reporting interval for the micro:bit's accelerometer, in milliseconds.

when Microbit_Accelerometer1 AccelerometerPeriodReceived Accelerometer_Period do

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

Parameters:

+ <code>Accelerometer_Period</code> (_number_) &mdash; The reporting period for the micro:bit's accelerometer, in milliseconds.

when Microbit_Accelerometer1 WroteAccelerometerPeriod Accelerometer_Period do