-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgesture_test.py
66 lines (51 loc) · 1.71 KB
/
gesture_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# Example using a character LCD connected to a Raspberry Pi or BeagleBone Black.
import time
import apds9960 as GestureSensor
from apds9960_constants import *
import RPi.GPIO as GPIO
SENSOR_INTERRUPT = 4
def intcallback(channel):
while sensor.isGestureAvailable():
motion=sensor.readGesture()
if motion == Directions.DIR_NONE:
print("None")
if motion == Directions.DIR_LEFT:
print("Left")
if motion == Directions.DIR_RIGHT:
print("Right")
if motion == Directions.DIR_UP:
print("Up")
if motion == Directions.DIR_DOWN:
print("Down")
if motion == Directions.DIR_NEAR:
print("Near")
if motion == Directions.DIR_FAR:
print("Far")
sensor.enableGestureSensor(True)
sensor = GestureSensor.APDS9960(bus=1)
sensor.initDevice()
sensor.resetGestureParameters()
sensor.setGestureGain(GGAIN_2X)
sensor.setGestureLEDDrive(LED_DRIVE_25MA)
sensor.enableGestureSensor(True)
time.sleep(0.5)
input("Press Enter when ready\n>")
GPIO.setmode(GPIO.BCM)
GPIO.setup(SENSOR_INTERRUPT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(SENSOR_INTERRUPT, GPIO.FALLING, callback=intcallback)
if sensor.isGestureAvailable():
sensor.readGesture()
try:
while True:
time.sleep(1)
#light = sensor.readAmbientLight()
#print "light={}".format(light)
#red = sensor.readRedLight()
#green = sensor.readGreenLight()
#blue = sensor.readBlueLight()
#print "Light Colors({},{},{})".format(red,green,blue)
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
sensor.resetGestureParameters()
print("Done")