The Plasma library is intended to drive APA102 / DotStar™ or WS2812 / NeoPixel™ LEDs on the Plasma 2040 board, though it can be used with your own custom pins/wiring.
- [Notes On PIO Limitations](#notes-on-pio-limitations)
The WS2812 and APA102 drivers use the PIO hardware on the RP2040. There are only two PIOs with four state machines each, placing a hard limit on how many separate LED strips you can drive.
In most cases you'll use `0` for PIO and `0` for PIO state-machine, but you should change these if you plan on running different strand types together, or if you're using something else that uses PIO.
Start the LED strip by calling `start`. This sets up a timer which tells the RP2040 to DMA the pixel data into the PIO (a fast, asyncronous memory->peripheral copy) at the specified framerate.
Start the LED strip by calling `start`. This sets up a timer which tells the RP2040 to DMA the pixel data into the PIO (a fast, asyncronous memory->peripheral copy) at the specified framerate.
```python
led_strip.start(FPS)
```
### Set An LED
You can set the colour of an LED in either the RGB colourspace, or HSV (Hue, Saturation, Value). HSV is useful for creating rainbow patterns.
#### RGB
Set the first LED - `0` - to Purple `255, 0, 255`:
APA102 pixels support global brightness, allowing their brightness to be specified independent of their colour. You can set the overall brightness of your strip by calling:
```python
led_strip.set_brightness(15)
```
You can set brightness from `0` to `31`. This directly maps to the 5-bit brightness value sent to the APA102 LEDs.
To get the button state, call `.read()`. If the button is held down, then this will return `True` at the interval specified by `repeat_time` until `hold_time` is reached, at which point it will return `True` every `repeat_time / 3` milliseconds. This is useful for rapidly increasing/decreasing values such as hue:
Plasma 2040 feasures low-side current sensing, letting you measure how much current a strip of LEDs is drawing. This could be used just for monitoring, or as a way to reduce the maximum brightness of a strip to keep its current draw within the range of the USB port or power supply being used.
The `pimoroni` module contains an `Analog` class to simplify the reading of this current draw.
```python
Analog(pin, amplifier_gain=1, resistor=0)
```
The `plasma` module contains a `plasma2040` sub module with constants for the current sensing:
*`plasma2040.CURRENT_SENSE` = 29
*`plasma2040.ADC_GAIN` = 50
*`plasma2040.SHUNT_RESISTOR` = 0.015
### Analog
Import the `Analog` class from `pimoroni` and the pin and gain constants for the current sensing:
```python
from pimoroni import Analog
from plasma import plasma2040
```
And set up an instance of `Analog` for the current sensing:
```python
sense = Analog(plasma2040.CURRENT_SENSE, plasma2040.ADC_GAIN, plasma2040.SHUNT_RESISTOR)
```
To read the current draw, call `.read_current()`. The returned value will be in amps (A):