forked from buxtonpaul/APDS-9960-PY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor_test.py
53 lines (41 loc) · 1.39 KB
/
sensor_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
#!/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):
#global sensor
print("Interrupt handler called!")
prox=sensor.readProximity()
print("Proximity = {}".format(prox))
sensor.clearProximityInt()
sensor = GestureSensor.APDS9960(bus=1)
sensor.initDevice()
sensor.setProximityGain(PGAIN_2X)
sensor.setProximityIntLowThreshold(0)
sensor.setProximityIntHighThreshold(100)
sensor.enableProximitySensor(1)
sensor.enableLightSensor(0)
sensor.clearProximityInt()
time.sleep(0.5)
prox = sensor.readProximity()
print("Proximity = {}".format(prox))
input("Press Enter when ready\n>")
GPIO.setmode(GPIO.BCM)
# GPIO 4 set up as an input, pulled up, pulled down on interrupt
GPIO.setup(SENSOR_INTERRUPT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(SENSOR_INTERRUPT, GPIO.FALLING, callback=intcallback)
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
print("Done")