Read Accelerometer Sensor
Learn:
Requirements
- Android smartphone - example does not run on the emulator
accelerometer.py
import android
import time
droid = android.Android()
dt = 100 #100ms between sensings
endTime = 3000 #sample for 3000ms
timeSensed=0
droid.startSensingTimed(2,dt)
while timeSensed <= endTime:
print droid.sensorsReadAccelerometer().result
time.sleep(dt/1000.0)
timeSensed+=dt
droid.stopSensing()
Code Explained
droid.startSensingTimed(2,dt)
startSensingTimed(Integer sensorNumber: 1 = All, 2 = Accelerometer, 3 = Magnetometer and 4 = Light,
Integer delayTime: Minimum time between readings in milliseconds)
Starts recording sensor data to be available for polling. Generates "sensors" events.
print droid.sensorsReadAccelerometer().result
Returns the most recently received accelerometer values as a List of Floats [(acceleration on the) X axis, Y axis, Z axis].
Scan the script to your smartphone using the Test EMANT380 app or download to PC/Emulator
- Launch Test EMANT380 app. (Bluetooth must be enabled)
- Tap Scan Files. (ZXing barcode scanner app must be installed)
- Scan the barcode and the script(s) to your SL4A list.