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()
12sensor = adafruit_vcnl4010.VCNL4010(i2c)
13
14# You can optionally adjust the sensor LED current.  The default is 200mA
15# which is the maximum value.  Note this is only set in 10mA increments.
16# sensor.led_current_mA = 120  # Set 120 mA LED current
17
18# You can also adjust the measurement frequency for the sensor.  The default
19# is 390.625 khz, but these values are possible to set too:
20# - FREQUENCY_3M125: 3.125 Mhz
21# - FREQUENCY_1M5625: 1.5625 Mhz
22# - FREQUENCY_781K25: 781.25 Khz
23# - FREQUENCY_390K625: 390.625 Khz (default)
24# sensor.frequency = adafruit_vcnl4010.FREQUENCY_3M125  # 3.125 Mhz
25
26# Main loop runs forever printing the proximity and light level.
27while True:
28    proximity = sensor.proximity  # Proximity has no units and is a 16-bit
29    # value.  The LOWER the value the further
30    # an object from the sensor (up to ~200mm).
31    print("Proximity: {0}".format(proximity))
32    ambient_lux = sensor.ambient_lux
33    print("Ambient light: {0} lux".format(ambient_lux))
34    time.sleep(1.0)