Simple test

Ensure your device works with this simple test.

examples/apds9960_color_simpletest.py
 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    # create some variables to store the color data in
16
17    # wait for color data to be ready
18    while not apds.color_data_ready:
19        time.sleep(0.005)
20
21    # get the data and print the different channels
22    r, g, b, c = apds.color_data
23    print("red: ", r)
24    print("green: ", g)
25    print("blue: ", b)
26    print("clear: ", c)
27
28    print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
29    print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
30    time.sleep(0.5)

Gesture Example

Show how to use the device with simple gestures

examples/apds9960_gesture_simpletest.py
 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")

Proximity Example

Example showing proximity feature

examples/apds9960_proximity_simpletest.py
 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)
10apds = APDS9960(i2c)
11
12apds.enable_proximity = True
13apds.proximity_interrupt_threshold = (0, 175)
14apds.enable_proximity_interrupt = True
15
16while True:
17    # print the proximity reading when the interrupt pin goes low
18    if not int_pin.value:
19        print(apds.proximity)
20
21        # clear the interrupt
22        apds.clear_interrupt()

Color Example

Example showing how to get RGB values

examples/apds9960_color_simpletest.py
 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    # create some variables to store the color data in
16
17    # wait for color data to be ready
18    while not apds.color_data_ready:
19        time.sleep(0.005)
20
21    # get the data and print the different channels
22    r, g, b, c = apds.color_data
23    print("red: ", r)
24    print("green: ", g)
25    print("blue: ", b)
26    print("clear: ", c)
27
28    print("color temp {}".format(colorutility.calculate_color_temperature(r, g, b)))
29    print("light lux {}".format(colorutility.calculate_lux(r, g, b)))
30    time.sleep(0.5)