您的位置:首页 > 编程语言 > Python开发

python for android : 手机摇一摇

2014-02-25 23:05 483 查看
手机摇一摇的测试脚本 sensor1.py

原理:x轴 y轴 z轴 有一接近或大于2g = 2*9.8= 19.6 即可

import android, time
droid = android.Android()
droid.startSensingTimed(2, 250)
time.sleep(1)
s2 = droid.sensorsReadAccelerometer().result
droid.stopSensing()
n =16 # threshold
x,y,z = s2
if abs(x)>n or abs(y)>n or abs(z)>n:
if abs(x)>n: print 'x=',x
if abs(y)>n: print 'y=',y
if abs(z)>n: print 'z=',z
droid.vibrate(500)
print 's2=',s2


参考: \sl4a\doc\SensorManagerFacade.html
startSensingTimed():

Starts recording sensor data to be available for polling.

sensorNumber (Integer) 1 = All, 2 = Accelerometer, 3 = Magnetometer and 4 = Light

delayTime (Integer) Minimum time between readings in milliseconds
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: