Skip to content

Instantly share code, notes, and snippets.

@mouuff
Created August 29, 2012 09:23
Show Gist options
  • Save mouuff/3508971 to your computer and use it in GitHub Desktop.
Save mouuff/3508971 to your computer and use it in GitHub Desktop.
Learning android api: sensors
import android
import time
droid = android.Android()
def readaccelerometer(read_time=1):
droid.startSensing(2)
time.sleep(read_time)
value = droid.sensorsReadAccelerometer().result
droid.stopSensing()
return value
def readlight(read_time=1):
droid.startSensing(4)
time.sleep(read_time)
value = droid.sensorsGetLight().result
droid.stopSensing()
return value
def isplate():
data = readaccelerometer()
if not int(data[0]) and not int(data[1]):
return True
return False
def ishiden():
if readlight() <= 160:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment