-
Notifications
You must be signed in to change notification settings - Fork 28
/
test_ambient.py
38 lines (32 loc) · 900 Bytes
/
test_ambient.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
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)
try:
# Interrupt-Event hinzufuegen, steigende Flanke
GPIO.add_event_detect(7, GPIO.FALLING, callback = intH)
print("Light Sensor Test")
print("=================")
apds.enableLightSensor()
oval = -1
while True:
sleep(0.25)
if apds.isLightAvailable():
val = apds.readAmbientLight()
r = apds.readRedLight()
g = apds.readGreenLight()
b = apds.readBlueLight()
if val != oval:
print("AmbientLight={} (R: {}, G: {}, B: {})".format(val, r, g, b))
oval = val
finally:
GPIO.cleanup()
print("Bye")