Skip to content

improving_docs #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions adafruit_vcnl4010.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
from micropython import const
Expand Down Expand Up @@ -67,7 +68,38 @@


class VCNL4010:
"""Vishay VCNL4010 proximity and ambient light sensor."""
"""Vishay VCNL4010 proximity and ambient light sensor.

:param ~busio.I2C i2c: The I2C bus the VCNL4010 is connected to
:param int address: (optional) The I2C address of the device. Defaults to :const:`0x13`

**Quickstart: Importing and using the VCNL4010**

Here is an example of using the :class:`VCNL4010` class.
First you will need to import the libraries to use the sensor

.. code-block:: python

import board
import adafruit_vcnl4010

Once this is done you can define your `board.I2C` object and define your sensor object

.. code-block:: python

i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_vcnl4010.VCNL4010(i2c)

Now you have access to the :attr:`sensor.proximity` and
:attr:`ambient_lux` attributes


.. code-block:: python

proximity = sensor.proximity
ambient_lux = sensor.ambient_lux

"""

# Class-level buffer for reading and writing data with the sensor.
# This reduces memory allocations but means the code is not re-entrant or
Expand Down Expand Up @@ -127,7 +159,7 @@ def led_current_mA(self):
supports current changes in 10mA increments, i.e. a value of 123 mA will
actually use 120 mA. See the datasheet for how the LED current impacts
proximity measurements, and the led_current property to explicitly set
values without quanitization or unit conversion.
values without quantization or unit conversion.
"""
return self.led_current * 10

Expand Down Expand Up @@ -186,7 +218,7 @@ def proximity(self):
def ambient(self):
"""The detected ambient light in front of the sensor. This is
a unit-less unsigned 16-bit value (0-65535) with higher values for
more detected light. See the ambient_lux property for a value in lux.
more detected light. See the :attr:`ambient_lux property` for a value in lux.
"""
# Clear interrupt.
status = self._read_u8(_VCNL4010_INTSTAT)
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Table of Contents
.. toctree::
:caption: Tutorials

VCNL4010 Proximity/Light sensor Learning Guide <https://learn.adafruit.com/using-vcnl4010-proximity-sensor/>

.. toctree::
:caption: Related Products

Expand Down
6 changes: 1 addition & 5 deletions examples/vcnl4010_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
# Simple demo of the VCNL4010 proximity and light sensor.
# Will print the proximity and ambient light every second.
import time

import board
import busio

import adafruit_vcnl4010


# Initialize I2C bus and VCNL4010 module.
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
sensor = adafruit_vcnl4010.VCNL4010(i2c)

# You can optionally adjust the sensor LED current. The default is 200mA
Expand Down