手机摇一摇的测试脚本 sensor1.py
原理:x轴 y轴 z轴 有一接近或大于2g = 2*9.8= 19.6 即可
import android, time droid = android.Android() droid.startSensingTimed(1, 250) time.sleep(1) s4 = droid.sensorsReadAccelerometer().result droid.stopSensing() n=17 # threshold x,y,z =s4 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 ‘s4=‘,s4