forked from liske/python-apds9960
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gesture.py
45 lines (36 loc) · 963 Bytes
/
test_gesture.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
from apds9960.const import *
from apds9960 import APDS9960
import RPi.GPIO as GPIO
import smbus
from time import sleep
port = 1
bus = smbus.SMBus(port)
apds = APDS9960(bus)
def intH(channel):
print("INTERRUPT")
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN)
dirs = {
APDS9960_DIR_NONE: "none",
APDS9960_DIR_LEFT: "left",
APDS9960_DIR_RIGHT: "right",
APDS9960_DIR_UP: "up",
APDS9960_DIR_DOWN: "down",
APDS9960_DIR_NEAR: "near",
APDS9960_DIR_FAR: "far",
}
try:
# Interrupt-Event hinzufuegen, steigende Flanke
GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
apds.setProximityIntLowThreshold(50)
print("Gesture Test")
print("============")
apds.enableGestureSensor()
while True:
sleep(0.5)
if apds.isGestureAvailable():
motion = apds.readGesture()
print("Gesture={}".format(dirs.get(motion, "unknown")))
finally:
GPIO.cleanup()
print("Bye")