|
| 1 | +# APA102 Library |
| 2 | + |
| 3 | +[](https://travis-ci.com/pimoroni/apa102-python) |
| 4 | +[](https://coveralls.io/github/pimoroni/apa102-python?branch=master) |
| 5 | +[](https://pypi.python.org/pypi/apa102) |
| 6 | +[](https://pypi.python.org/pypi/apa102) |
| 7 | + |
| 8 | +# Pre-requisites |
| 9 | + |
| 10 | +You must enable SPI: |
| 11 | + |
| 12 | +* spi: `sudo raspi-config nonint do_spi 0` |
| 13 | + |
| 14 | +You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configuration UI to enable interfaces. |
| 15 | + |
| 16 | +# Installing |
| 17 | + |
| 18 | +Stable library from PyPi: |
| 19 | + |
| 20 | +* Just run `python3 -m pip install apa102` |
| 21 | + |
| 22 | +Latest/development library from GitHub: |
| 23 | + |
| 24 | +* `git clone https://github.com/pimoroni/apa102-python` |
| 25 | +* `cd apa102-python` |
| 26 | +* `sudo ./install.sh` |
| 27 | + |
| 28 | +# Usage |
| 29 | + |
| 30 | +The APA102 class will attempt to use spidev or RPi.GPIO depending on which pins you specify. |
| 31 | + |
| 32 | +For example; three RGB LEDs connected to SPI pins 10 and 11 with chip-select 8 (CE0): |
| 33 | + |
| 34 | +```python |
| 35 | +from apa102 import APA102 |
| 36 | +lights = APA102(3, 10, 11, 8) |
| 37 | +``` |
| 38 | + |
| 39 | +You can then set individual pixels with `set_pixel`: |
| 40 | + |
| 41 | +``` |
| 42 | +lights.set_pixel(0, 255, 0, 0) # Pixel 1 to Red |
| 43 | +lights.set_pixel(1, 0, 255, 0) # Pixel 2 to Green |
| 44 | +lights.set_pixel(2, 0, 0, 255) # Pixel 3 to Blue |
| 45 | +``` |
| 46 | + |
| 47 | +Pixels are zero-indexed and accept Red, Green and Blue colour values from 0 to 255. |
| 48 | + |
| 49 | +# Changelog |
| 50 | +0.0.1 |
| 51 | +----- |
| 52 | + |
| 53 | +* Initial Release |
0 commit comments