Skip to content

Commit 5d35059

Browse files
Add examples for APDS9960.
1 parent 86d071b commit 5d35059

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

examples/APDS9960_ambient.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# From https://github.com/liske/python-apds9960
2+
# This example requires apds9960 library.
3+
4+
from apds9960 import APDS9960
5+
from EasyMCP2221 import smbus
6+
from time import sleep
7+
8+
bus = smbus.SMBus(1)
9+
apds = APDS9960(bus)
10+
11+
print("Light Sensor Test")
12+
print("=================")
13+
14+
apds.enableLightSensor()
15+
oval = -1
16+
while True:
17+
sleep(0.25)
18+
if apds.isLightAvailable():
19+
val = apds.readAmbientLight()
20+
r = apds.readRedLight()
21+
g = apds.readGreenLight()
22+
b = apds.readBlueLight()
23+
if val != oval:
24+
print("AmbientLight={} (R: {}, G: {}, B: {})".format(val, r, g, b))
25+
oval = val

examples/APDS9960_prox.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# From https://github.com/liske/python-apds9960
2+
# This example requires apds9960 library.
3+
4+
from apds9960 import APDS9960
5+
from EasyMCP2221 import SMBus
6+
from time import sleep
7+
8+
bus = SMBus(1)
9+
apds = APDS9960(bus)
10+
11+
print("Proximity Sensor Test")
12+
print("=====================")
13+
14+
apds.enableProximitySensor()
15+
oval = -1
16+
while True:
17+
sleep(0.25)
18+
val = apds.readProximity()
19+
if val != oval:
20+
print("proximity={}".format(val))
21+
oval = val

0 commit comments

Comments
 (0)