Skip to content

improving_docs #29

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
22 changes: 10 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ To install in a virtual environment in your current project:
Usage Example
=============

.. code-block:: python
.. code-block:: python3

import board
import busio
import digitalio
from adafruit_apds9960.apds9960 import APDS9960

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
int_pin = digitalio.DigitalInOut(board.D5)
apds = APDS9960(i2c, interrupt_pin=int_pin)

Expand All @@ -85,30 +84,29 @@ Basics

Of course, you must import i2c bus device, board pins, and the library:

.. code:: python
.. code:: python3


from board import SCL, SDA, A1
import board
from adafruit_apds9960.apds9960 import APDS9960
import busio
import digitalio

To set-up the device to gather data, initialize the I2CDevice using SCL
and SDA pins. Then initialize the library. Optionally provide an interrupt
pin for proximity detection.

.. code:: python
.. code:: python3

int_pin = digitalio.DigitalInOut(A1)
i2c = busio.I2C(SCL, SDA)
int_pin = digitalio.DigitalInOut(board.A1)
i2c = board.I2C()
apds = APDS9960(i2c, interrupt_pin=int_pin)

Gestures
--------

To get a gesture, see if a gesture is available first, then get the gesture Code

.. code:: python
.. code:: python3

gesture = apds.gesture()
if gesture == 1:
Expand All @@ -126,7 +124,7 @@ Color Measurement
To get a color measure, enable color measures, wait for color data,
then get the color data.

.. code:: python
.. code:: python3

apds.enable_color = True

Expand All @@ -141,7 +139,7 @@ Proximity Detection

To check for a object in proximity, see if a gesture is available first, then get the gesture Code

.. code:: python
.. code:: python3

apds.enable_proximity = True

Expand Down
47 changes: 47 additions & 0 deletions adafruit_apds9960/apds9960.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
detection.

* Author(s): Michael McWethy

Implementation Notes
--------------------

**Hardware:**

* Adafruit `APDS9960 Proximity, Light, RGB, and Gesture Sensor
<https://www.adafruit.com/product/3595>`_ (Product ID: 3595)

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import time
import digitalio
Expand Down Expand Up @@ -81,6 +96,38 @@
class APDS9960:
"""
APDS9900 provide basic driver services for the ASDS9960 breakout board

:param ~busio.I2C i2c: The I2C bus the BME280 is connected to
:param ~microcontroller.Pin interrupt_pin: Interrupt pin. Defaults to `None`
:param int address: The I2C device address. Defaults to :const:`0x39`
:param int integration_time: integration time. Defaults to :const:`0x01`
:param int gain: Device gain. Defaults to :const:`0x01`
:param int rotation: rotation of the device. Defaults to :const:`0`


**Quickstart: Importing and using the APDS9960**

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

.. code-block:: python

import board
from adafruit_apds9960.apds9960 import APDS9960

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
apds = APDS9960(i2c)

Now you have access to the :attr:`sensor.proximity` attribute

.. code-block:: python

proximity = apds.proximity

"""

_gesture_enable = RWBit(APDS9960_ENABLE, 6)
Expand Down
22 changes: 22 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,32 @@ Ensure your device works with this simple test.
:caption: examples/apds9960_color_simpletest.py
:linenos:


Gesture Example
---------------

Show how to use the device with simple gestures

.. literalinclude:: ../examples/apds9960_gesture_simpletest.py
:caption: examples/apds9960_gesture_simpletest.py
:linenos:


Proximity Example
-----------------

Example showing proximity feature

.. literalinclude:: ../examples/apds9960_proximity_simpletest.py
:caption: examples/apds9960_proximity_simpletest.py
:linenos:


Color Example
---------------

Example showing how to get RGB values

.. literalinclude:: ../examples/apds9960_color_simpletest.py
:caption: examples/apds9960_color_simpletest.py
:linenos:
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

Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor Learning Guide <https://learn.adafruit.com/adafruit-apds9960-breakout>

.. toctree::
:caption: Related Products

Expand Down
3 changes: 1 addition & 2 deletions examples/apds9960_color_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import time
import board
import busio
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_apds9960 import colorutility

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
apds = APDS9960(i2c)
apds.enable_color = True

Expand Down
5 changes: 2 additions & 3 deletions examples/apds9960_gesture_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

from board import SCL, SDA
import busio
import board
from adafruit_apds9960.apds9960 import APDS9960

i2c = busio.I2C(SCL, SDA)
i2c = board.I2C()

apds = APDS9960(i2c)
apds.enable_proximity = True
Expand Down
3 changes: 1 addition & 2 deletions examples/apds9960_proximity_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# SPDX-License-Identifier: MIT

import board
import busio
import digitalio
from adafruit_apds9960.apds9960 import APDS9960

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
int_pin = digitalio.DigitalInOut(board.D5)
apds = APDS9960(i2c, interrupt_pin=int_pin)

Expand Down
3 changes: 1 addition & 2 deletions examples/apds9960_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

import time
import board
import busio
from adafruit_apds9960.apds9960 import APDS9960

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
apds = APDS9960(i2c)

apds.enable_proximity = True
Expand Down