Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6from adafruit_apds9960.apds9960 import APDS9960
7
8i2c = board.I2C()
9apds = APDS9960(i2c)
10
11apds.enable_proximity = True
12
13while True:
14 print(apds.proximity)
15 time.sleep(0.2)
Proximity Example¶
Example illustrating proximity detection
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import board
5import digitalio
6from adafruit_apds9960.apds9960 import APDS9960
7
8i2c = board.I2C()
9int_pin = digitalio.DigitalInOut(board.D5)
10int_pin.switch_to_input(pull=digitalio.Pull.UP)
11apds = APDS9960(i2c)
12
13# set the interrupt threshold to fire when proximity reading goes above 175
14apds.proximity_interrupt_threshold = (0, 175)
15
16# assert the interrupt pin when the proximity interrupt is triggered
17apds.enable_proximity_interrupt = True
18
19# enable the sensor's proximity engine
20apds.enable_proximity = True
21
22while True:
23 # print the proximity reading when the interrupt pin goes low
24 if not int_pin.value:
25 print(apds.proximity)
26
27 # clear the interrupt
28 apds.clear_interrupt()
Gesture Example¶
Example illustrating gesture detection
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import board
5from adafruit_apds9960.apds9960 import APDS9960
6
7i2c = board.I2C()
8
9apds = APDS9960(i2c)
10apds.enable_proximity = True
11apds.enable_gesture = True
12
13# Uncomment and set the rotation if depending on how your sensor is mounted.
14# apds.rotation = 270 # 270 for CLUE
15
16while True:
17 gesture = apds.gesture()
18
19 if gesture == 0x01:
20 print("up")
21 elif gesture == 0x02:
22 print("down")
23 elif gesture == 0x03:
24 print("left")
25 elif gesture == 0x04:
26 print("right")
Color Example¶
Example illustrating color detection
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board
6from adafruit_apds9960.apds9960 import APDS9960
7from adafruit_apds9960 import colorutility
8
9i2c = board.I2C()
10apds = APDS9960(i2c)
11apds.enable_color = True
12
13
14while True:
15 # wait for color data to be ready
16 while not apds.color_data_ready:
17 time.sleep(0.005)
18
19 # get the data and print the different channels
20 r, g, b, c = apds.color_data
21 print("red: ", r)
22 print("green: ", g)
23 print("blue: ", b)
24 print("clear: ", c)
25
26 print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
27 print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
28 time.sleep(0.5)