Skip to content

Commit dc80cf9

Browse files
committed
Linting fixes
1 parent d94997d commit dc80cf9

3 files changed

Lines changed: 91 additions & 82 deletions

File tree

REFERENCE.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ This is the library reference for the [Pimoroni Inventor HAT Mini](https://pimor
4545
## Getting Started
4646

4747
To start coding your Inventor HAT Mini, you will need to add the following lines to the start of your code file.
48+
4849
```python
4950
from inventorhatmini import InventorHATMini
5051
board = InventorHATMini()
5152
```
53+
5254
This will create a `InventorHATMini` class called `board` that will be used in the rest of the examples going forward.
5355

5456

@@ -60,6 +62,7 @@ Inventor HAT Mini has a single button on top, labelled **User**. This can be rea
6062
state = board.switch_pressed()
6163
```
6264

65+
6366
## Reading Voltage
6467

6568
Inventor HAT Mini can measure the voltage its motors and servos are being powered by. On an unmodified board this is also the voltage of the Raspberry Pi's 5V output.
@@ -70,10 +73,12 @@ The voltage can be measured by calling `.read_voltage()`:
7073
voltage = board.read_voltage()
7174
```
7275

76+
7377
## GPIOs
7478

7579
There are four GPIO pins on Inventor HAT Mini. These can be used as digital outputs, digital inputs, and analog inputs. There is also a special mode where a pair of GPIO pins can be used as rotary encoder inputs.
7680

81+
7782
### Setup
7883

7984
To start using a GPIO pin, first import one of the handy constants used to reference them (see [GPIO Constants](#gpio-constants)). For example, to use the first GPIO pin:
@@ -97,6 +102,7 @@ from ioexpander import OUT
97102
from ioexpander import ADC
98103
```
99104

105+
100106
### Mode
101107

102108
With the intended constants imported, the mode of a GPIO pin can be set by calling `.gpio_pin_mode(gpio, mode)`:
@@ -111,6 +117,7 @@ It is also possible to read the current mode of a GPIO pin by calling `.gpio_pin
111117
mode = board.gpio_pin_mode(GPIO_1)
112118
```
113119

120+
114121
### As Input or ADC
115122

116123
The current value of an GPIO pin in input or ADC mode can be read by calling `.gpio_pin_value(gpio)`:
@@ -178,6 +185,7 @@ These give you access to objects that handle the motor and encoder functionality
178185
* `board.motors`: [`Motor` object](https://github.com/pimoroni/ioe-python/blob/master/docs/motor.md)
179186
* `board.encoders`: [`Encoder` object](https://github.com/pimoroni/ioe-python/blob/master/docs/encoder.md)
180187

188+
181189
### Enabling and Disabling
182190

183191
The motor outputs of Inventor HAT Mini can be enabled and disabled at any time by calling `.enable_motors()` and `.disable_motors()`. These functions call both motor's respective `.enable()` and `.disable()` functions.
@@ -361,7 +369,7 @@ For details of what can be done with this object, check out its documentation pa
361369

362370
## Audio
363371

364-
Inventor HAT Mini features an onboard I2S audio amplifier, letting it play any sounds created by your Raspberry Pi, from any source, be it a web browser, music player, or from code.
372+
Inventor HAT Mini features an onboard I2S audio amplifier, letting it play any sounds created by your Raspberry Pi, from any source, be it a web browser, music player, or from code.
365373

366374
There are many ways sound can be created from code, some examples of which can be found in [examples/audio](/examples/audio/).
367375

docs/plasma.md

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
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.

inventorhatmini/plasma.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from rpi_ws281x import PixelStrip
21
from colorsys import hsv_to_rgb
32

3+
from rpi_ws281x import PixelStrip
4+
45
from inventorhatmini.errors import LED_INIT_FAILED
56

67

0 commit comments

Comments
 (0)