Simple test

Ensure your device works with this simple test.

examples/vcnl4010_simpletest.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
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
# SPDX-License-Identifier: MIT

# Simple demo of the VCNL4010 proximity and light sensor.
# Will print the proximity and ambient light every second.
import time
import board
import adafruit_vcnl4010


i2c = board.I2C()
sensor = adafruit_vcnl4010.VCNL4010(i2c)

# You can optionally adjust the sensor LED current.  The default is 200mA
# which is the maximum value.  Note this is only set in 10mA increments.
# sensor.led_current_mA = 120  # Set 120 mA LED current

# You can also adjust the measurement frequency for the sensor.  The default
# is 390.625 khz, but these values are possible to set too:
# - FREQUENCY_3M125: 3.125 Mhz
# - FREQUENCY_1M5625: 1.5625 Mhz
# - FREQUENCY_781K25: 781.25 Khz
# - FREQUENCY_390K625: 390.625 Khz (default)
# sensor.frequency = adafruit_vcnl4010.FREQUENCY_3M125  # 3.125 Mhz

# Main loop runs forever printing the proximity and light level.
while True:
    proximity = sensor.proximity  # Proximity has no units and is a 16-bit
    # value.  The LOWER the value the further
    # an object from the sensor (up to ~200mm).
    print("Proximity: {0}".format(proximity))
    ambient_lux = sensor.ambient_lux
    print("Ambient light: {0} lux".format(ambient_lux))
    time.sleep(1.0)