Simple test

Ensure your device works with this simple test.

examples/vcnl4010_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of the VCNL4010 proximity and light sensor.
 5# Will print the proximity and ambient light every second.
 6import time
 7import board
 8import adafruit_vcnl4010
 9
10
11i2c = board.I2C()  # uses board.SCL and board.SDA
12# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
13sensor = adafruit_vcnl4010.VCNL4010(i2c)
14
15# You can optionally adjust the sensor LED current.  The default is 200mA
16# which is the maximum value.  Note this is only set in 10mA increments.
17# sensor.led_current_mA = 120  # Set 120 mA LED current
18
19# You can also adjust the measurement frequency for the sensor.  The default
20# is 390.625 khz, but these values are possible to set too:
21# - FREQUENCY_3M125: 3.125 Mhz
22# - FREQUENCY_1M5625: 1.5625 Mhz
23# - FREQUENCY_781K25: 781.25 Khz
24# - FREQUENCY_390K625: 390.625 Khz (default)
25# sensor.frequency = adafruit_vcnl4010.FREQUENCY_3M125  # 3.125 Mhz
26
27# Main loop runs forever printing the proximity and light level.
28while True:
29    proximity = sensor.proximity  # Proximity has no units and is a 16-bit
30    # value.  The LOWER the value the further
31    # an object from the sensor (up to ~200mm).
32    print("Proximity: {0}".format(proximity))
33    ambient_lux = sensor.ambient_lux
34    print("Ambient light: {0} lux".format(ambient_lux))
35    time.sleep(1.0)