/ README.rst
README.rst
  1  CircuitPython_RGBLED
  2  ====================
  3  .. image:: https://readthedocs.org/projects/adafruit-circuitpython-rgbled/badge/?version=latest
  4      :target: https://circuitpython.readthedocs.io/projects/rgbled/en/latest/
  5      :alt: Documentation Status
  6  
  7  .. image:: https://img.shields.io/discord/327254708534116352.svg
  8      :target: https://adafru.it/discord
  9      :alt: Discord
 10  
 11  .. image:: https://github.com/adafruit/Adafruit_CircuitPython_RGBLED/workflows/Build%20CI/badge.svg
 12      :target: https://github.com/adafruit/Adafruit_CircuitPython_RGBLED/actions
 13      :alt: Build Status
 14  
 15  CircuitPython driver for RGB LEDs. Works with native microcontroller pins,
 16  `Adafruit Blinka <https://github.com/adafruit/Adafruit_Blinka>`_, or the `PCA9685 PWM driver <https://www.adafruit.com/product/815>`_.
 17  
 18  Dependencies
 19  =============
 20  This driver depends on:
 21  
 22  * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
 23  * `SimpleIO Library <https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO>`_
 24  
 25  Please ensure all dependencies are available on the CircuitPython filesystem.
 26  This is easily achieved by downloading
 27  `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
 28  
 29  Installing from PyPI
 30  --------------------
 31  On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
 32  PyPI <https://pypi.org/project/adafruit-circuitpython-rgbled/>`_. To install for current user:
 33  
 34  .. code-block:: shell
 35  
 36      pip3 install adafruit-circuitpython-rgbled
 37  
 38  To install system-wide (this may be required in some cases):
 39  
 40  .. code-block:: shell
 41  
 42      sudo pip3 install adafruit-circuitpython-rgbled
 43  
 44  To install in a virtual environment in your current project:
 45  
 46  .. code-block:: shell
 47  
 48      mkdir project-name && cd project-name
 49      python3 -m venv .env
 50      source .env/bin/activate
 51      pip3 install adafruit-circuitpython-rgbled
 52  
 53  Usage Example
 54  ==============
 55  
 56  Initialize a common-cathode RGB LED with three PWM-capable pins.
 57  
 58  .. code-block:: python
 59  
 60      import board
 61      import adafruit_rgbled
 62  
 63      # Pin the Red LED is connected to
 64      RED_LED = board.D5
 65  
 66      # Pin the Green LED is connected to
 67      GREEN_LED = board.D6
 68  
 69      # Pin the Blue LED is connected to
 70      BLUE_LED = board.D7
 71  
 72      # Create a RGB LED object
 73      led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
 74  
 75  Initialize a common-anode RGB LED with three PWM-capable pins 
 76  
 77  .. code-block:: python
 78  
 79      import board
 80      import adafruit_rgbled
 81  
 82      # Pin the Red LED is connected to
 83      RED_LED = board.D5
 84  
 85      # Pin the Green LED is connected to
 86      GREEN_LED = board.D6
 87  
 88      # Pin the Blue LED is connected to
 89      BLUE_LED = board.D7
 90  
 91      # Create a RGB LED object
 92      led = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED, invert_pwm = True)
 93  
 94  Set the RGB LED's color to a RGB Tuple (Red, Green, Blue).
 95  
 96  .. code-block:: python
 97  
 98      led.color = (255, 0, 0)
 99  
100  Set the RGB LED's color to a 24-bit integer (in hex syntax), 0x100000.
101  
102  .. code-block:: python
103      
104      led.color = 0x100000
105  
106  Setting a common-anode RGB LED using a ContextManager:
107  
108  .. code-block:: python
109  
110      import board
111      import adafruit_rgbled
112      with adafruit_rgbled.RGBLED(board.D5, board.D6, board.D7, invert_pwm = True) as rgb_led:
113          rgb_led.color = (0, 255, 0)
114  
115  Contributing
116  ============
117  
118  Contributions are welcome! Please read our `Code of Conduct
119  <https://github.com/adafruit/Adafruit_CircuitPython_RGBLED/blob/master/CODE_OF_CONDUCT.md>`_
120  before contributing to help this project stay welcoming.
121  
122  Documentation
123  =============
124  
125  For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.