AccelerometerSensor Component
Properties
available Returns whether the AccelerometerSensor hardware is available on the device.
Data type: boolean |
||
Designer Writable | false | |
Code Writeable | false | |
Code Readable | true |
let variable = accelerometersensorName.available |
enabled Specifies whether the sensor should generate events. If true, the sensor will generate events. Otherwise, no events are generated even if the device is accelerated or shaken.
Data type: boolean |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" enabled="true"> |
Code Writeable | true |
accelerometersensorName.enabled = true |
Code Readable | true |
let variable = accelerometersensorName.enabled |
legacyMode Prior to the release that added this property the AccelerometerSensor component passed through sensor values directly as received from the Android system. However these values do not compensate for tablets that default to Landscape mode, requiring the MIT App Inventor programmer to compensate. However compensating would result in incorrect results in Portrait mode devices such as phones. We now detect Landscape mode tablets and perform the compensation. However if your project is already compensating for the change, you will now get incorrect results. Although our preferred solution is for you to update your project, you can also just set this property to “true” and our compensation code will be deactivated. Note: We recommend that you update your project as we may remove this property in a future release.
Data type: boolean |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" legacyMode="true"> |
Code Writeable | false | |
Code Readable | false |
minimumInterval Specifies the minimum interval required between back-to-back Shaking events, in milliseconds. Once the phone starts being shaken, all further Shaking events will be ignored until the interval has elapsed.
Data type: number |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" minimumInterval="0"> |
Code Writeable | true |
accelerometersensorName.minimumInterval = 0 |
Code Readable | true |
let variable = accelerometersensorName.minimumInterval |
sensitivity Specifies the sensitivity of the accelerometer. Valid values are 'weak', 'moderate' and 'strong'. Can only be read after screen initialized.
Data type: string |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" sensitivity="weak"> |
Code Writeable | true |
accelerometersensorName.sensitivity = "weak" |
Code Readable | true |
let variable = accelerometersensorName.sensitivity |
xAccel Returns the acceleration in the X-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.
Data type: number |
||
Designer Writable | false | |
Code Writeable | false | |
Code Readable | true |
let variable = accelerometersensorName.xAccel |
yAccel Returns the acceleration in the Y-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.
Data type: number |
||
Designer Writable | false | |
Code Writeable | false | |
Code Readable | true |
let variable = accelerometersensorName.yAccel |
zAccel Returns the acceleration in the Z-dimension in SI units (m/s²). The sensor must be enabled to return meaningful values.
Data type: number |
||
Designer Writable | false | |
Code Writeable | false | |
Code Readable | true |
let variable = accelerometersensorName.zAccel |
class The styling class of the the component
Data type: string |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" class="Test class"> |
Code Writeable | false | |
Code Readable | false |
id The styling id of the the component
Data type: string |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" id="Test id"> |
Code Writeable | false | |
Code Readable | false |
name The name of the component that will be used to refer to it in code.
Data type: string |
||
Designer Writable | true |
<accelerometersensor name="accelerometersensorName" name="testComponent"> |
Code Writeable | false | |
Code Readable | false |
Methods
Method name | Description | Parameters | ||||
---|---|---|---|---|---|---|
addEventListener |
Method used to create event listeners. See Events below for samples. |
|
Events
Event name | Description | Parameters | ||||||
---|---|---|---|---|---|---|---|---|
accelerationChanged | Indicates the acceleration changed in the X, Y, and/or Z dimensions.accelerometersensorName.addEventListener( "accelerationChanged", function (xAccel, yAccel, zAccel) { //Your code here } ) |
|
||||||
shaking | Indicates the device started being shaken or continues to be shaken.accelerometersensorName.addEventListener( "shaking", function () { //Your code here } ) |
|