|
1 | | -# Inventor HAT Mini - Plasma <!-- omit in toc --> |
2 | | - |
3 | | -The Plasma class provides a means for controlling the onboard RGB LEDs of |
4 | | -[Inventor HAT Mini](https://shop.pimoroni.com/products/inventor-hat-mini). It shares familiarity with Inventor 2040 W's [Plasma library](https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/plasma/README.md), making it easy to port LED code between the two platforms. |
5 | | - |
6 | | -Under the hood Plasma uses the [rpi_ws281x package](https://pypi.org/project/rpi-ws281x/), which interacts with the necessary hardware via a `PixelStrip` class. |
7 | | - |
8 | | -- [Getting Started](#getting-started) |
9 | | -- [Set a LED](#set-a-led) |
10 | | - - [RGB](#rgb) |
11 | | - - [HSV](#hsv) |
12 | | -- [Clear all LEDs](#clear-all-leds) |
13 | | -- [Delayed Showing](#delayed-showing) |
14 | | -- [Function Reference](#function-reference) |
15 | | -- [DummyPlasma](#dummyplasma) |
16 | | - |
17 | | -## Getting Started |
18 | | - |
19 | | -`InventorHATMini` automatically creates a `Plasma` instance, accessable by `board.leds`. Instructions for creating a standalone instance are provided below for completeness. |
20 | | - |
21 | | -To construct a new `Plasma` instance, specify the number of LEDs, and the GPIO pin to use. See [GPIO Usage](https://github.com/rpi-ws281x/rpi-ws281x-python/tree/master/library#gpio-usage) for details on what pins are supported. |
22 | | - |
23 | | -```python |
24 | | -from inventorhatmini.plasma import Plasma |
25 | | - |
26 | | -LEDS = 30 |
27 | | -LED_DAT = 12 |
28 | | - |
29 | | -led_strip = Plasma(LEDS, LED_DAT) |
30 | | -``` |
31 | | - |
32 | | -## Set a LED |
33 | | - |
34 | | -You can set the colour of a LED in either the RGB colourspace, or HSV (Hue, Saturation, Value). HSV is useful for creating rainbow patterns. |
35 | | - |
36 | | -### RGB |
37 | | - |
38 | | -Set the first LED - `0` - to Purple `255, 0, 255`: |
39 | | - |
40 | | -```python |
41 | | -led_strip.set_rgb(0, 255, 0, 255) |
42 | | -``` |
43 | | - |
44 | | -### HSV |
45 | | - |
46 | | -Set the first LED - `0` - to Red `0.0`: |
47 | | - |
48 | | -```python |
49 | | -led_strip.set_hsv(0, 0.0, 1.0, 1.0) |
50 | | -``` |
51 | | - |
52 | | -## Clear all LEDs |
53 | | - |
54 | | -To turn off all the LEDs, the function `.clear()` can be called. This simply goes through each LED and sets its RGB colour to black, making them emit no light. |
55 | | - |
56 | | -This function is useful to have at the end of your code to turn the lights off, otherwise they will continue to show the last colours they were given. |
57 | | - |
58 | | -## Delayed Showing |
59 | | - |
60 | | -The `Plasma` class automatically applies changes to the LEDs immediately. However, sometimes this may not be wanted, and instead you want all LEDs to receive updated colours at the same time, regardless of how long the code ran that calculated them. |
61 | | - |
62 | | -For this purpose, the `.set_rgb()`, `.set_hsv()`, and `.clear()` functions include an optional parameter `show`, which by default is `True`. To avoid this "showing" include `show=False` in the relevant function calls. Then either the last call can include `show=True`, or a specific call to `.show()` can be made. |
63 | | - |
64 | | -## Function Reference |
65 | | - |
66 | | -Here is the complete list of functions available on the `Plasma` class: |
67 | | -```python |
68 | | -Plasma(num_leds, pin) |
69 | | -set_rgb(index, r, g, b, show=True) |
70 | | -set_hsv(index, h, s=1.0, v=1.0, show=True) |
71 | | -get(index) |
72 | | -clear(show=True) |
73 | | -show() |
74 | | -``` |
75 | | - |
76 | | -### DummyPlasma |
77 | | - |
78 | | -In addition to the `Plasma`class there is a `DummyPlasma` class. This class has all the same functions as the regular class, but does not interact with the LEDs. |
79 | | - |
80 | | -It was created to deal with the case where code may have been written that uses the LEDs but cannot be run with root user privilege (aka `sudo`). In this case, providing `init_leds=False` to `Inventor HAT Mini` causes it to create a `DummyPlasma` class for its `board.leds` variable, allowing such code to be run without further modification. |
| 1 | +# Inventor HAT Mini - Plasma <!-- omit in toc --> |
| 2 | + |
| 3 | +The Plasma class provides a means for controlling the onboard RGB LEDs of |
| 4 | +[Inventor HAT Mini](https://shop.pimoroni.com/products/inventor-hat-mini). It shares familiarity with Inventor 2040 W's [Plasma library](https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/plasma/README.md), making it easy to port LED code between the two platforms. |
| 5 | + |
| 6 | +Under the hood Plasma uses the [rpi_ws281x package](https://pypi.org/project/rpi-ws281x/), which interacts with the necessary hardware via a `PixelStrip` class. |
| 7 | + |
| 8 | +- [Getting Started](#getting-started) |
| 9 | +- [Set a LED](#set-a-led) |
| 10 | + - [RGB](#rgb) |
| 11 | + - [HSV](#hsv) |
| 12 | +- [Clear all LEDs](#clear-all-leds) |
| 13 | +- [Delayed Showing](#delayed-showing) |
| 14 | +- [Function Reference](#function-reference) |
| 15 | +- [DummyPlasma](#dummyplasma) |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +`InventorHATMini` automatically creates a `Plasma` instance, accessable by `board.leds`. Instructions for creating a standalone instance are provided below for completeness. |
| 20 | + |
| 21 | +To construct a new `Plasma` instance, specify the number of LEDs, and the GPIO pin to use. See [GPIO Usage](https://github.com/rpi-ws281x/rpi-ws281x-python/tree/master/library#gpio-usage) for details on what pins are supported. |
| 22 | + |
| 23 | +```python |
| 24 | +from inventorhatmini.plasma import Plasma |
| 25 | + |
| 26 | +LEDS = 30 |
| 27 | +LED_DAT = 12 |
| 28 | + |
| 29 | +led_strip = Plasma(LEDS, LED_DAT) |
| 30 | +``` |
| 31 | + |
| 32 | +## Set a LED |
| 33 | + |
| 34 | +You can set the colour of a LED in either the RGB colourspace, or HSV (Hue, Saturation, Value). HSV is useful for creating rainbow patterns. |
| 35 | + |
| 36 | +### RGB |
| 37 | + |
| 38 | +Set the first LED - `0` - to Purple `255, 0, 255`: |
| 39 | + |
| 40 | +```python |
| 41 | +led_strip.set_rgb(0, 255, 0, 255) |
| 42 | +``` |
| 43 | + |
| 44 | +### HSV |
| 45 | + |
| 46 | +Set the first LED - `0` - to Red `0.0`: |
| 47 | + |
| 48 | +```python |
| 49 | +led_strip.set_hsv(0, 0.0, 1.0, 1.0) |
| 50 | +``` |
| 51 | + |
| 52 | +## Clear all LEDs |
| 53 | + |
| 54 | +To turn off all the LEDs, the function `.clear()` can be called. This simply goes through each LED and sets its RGB colour to black, making them emit no light. |
| 55 | + |
| 56 | +This function is useful to have at the end of your code to turn the lights off, otherwise they will continue to show the last colours they were given. |
| 57 | + |
| 58 | +## Delayed Showing |
| 59 | + |
| 60 | +The `Plasma` class automatically applies changes to the LEDs immediately. However, sometimes this may not be wanted, and instead you want all LEDs to receive updated colours at the same time, regardless of how long the code ran that calculated them. |
| 61 | + |
| 62 | +For this purpose, the `.set_rgb()`, `.set_hsv()`, and `.clear()` functions include an optional parameter `show`, which by default is `True`. To avoid this "showing" include `show=False` in the relevant function calls. Then either the last call can include `show=True`, or a specific call to `.show()` can be made. |
| 63 | + |
| 64 | +## Function Reference |
| 65 | + |
| 66 | +Here is the complete list of functions available on the `Plasma` class: |
| 67 | +```python |
| 68 | +Plasma(num_leds, pin) |
| 69 | +set_rgb(index, r, g, b, show=True) |
| 70 | +set_hsv(index, h, s=1.0, v=1.0, show=True) |
| 71 | +get(index) |
| 72 | +clear(show=True) |
| 73 | +show() |
| 74 | +``` |
| 75 | + |
| 76 | +### DummyPlasma |
| 77 | + |
| 78 | +In addition to the `Plasma`class there is a `DummyPlasma` class. This class has all the same functions as the regular class, but does not interact with the LEDs. |
| 79 | + |
| 80 | +It was created to deal with the case where code may have been written that uses the LEDs but cannot be run with root user privilege (aka `sudo`). In this case, providing `init_leds=False` to `Inventor HAT Mini` causes it to create a `DummyPlasma` class for its `board.leds` variable, allowing such code to be run without further modification. |
0 commit comments