mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-12-08 20:39:01 +00:00
Docs clean up part 1
Big push on getting the docs cleaned up before 1.0. Proper wrapping of everything so it's decently viewable from the command line (or as decently viewable as markdown can be - the tables will never look great from the command line). Only one code change in this PR: rename bouncetime to bounce_time (everything else is PEP-8, so this probably should be too) and change its units to seconds from milliseconds (again, all other durations in the library are in seconds, so it feels inconsistent that this one isn't; for the sake of those who won't read the docs - which is most people - I figure consistency helps with guessing!).
This commit is contained in:
@@ -74,6 +74,9 @@ Boards & accessories:
|
||||
|
||||
## Getting started
|
||||
|
||||
See the [input devices](inputs.md) and [output devices](outputs.md) to get started. Also see the [boards & accessories](boards.md) page for examples of using the included accessories.
|
||||
See the [input devices](inputs.md) and [output devices](outputs.md) to get
|
||||
started. Also see the [boards & accessories](boards.md) page for examples of
|
||||
using the included accessories.
|
||||
|
||||
For common programs using multiple components together, see the [recipes](recipes.md) page.
|
||||
For common programs using multiple components together, see the
|
||||
[recipes](recipes.md) page.
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
# Input Devices
|
||||
|
||||
These input device component interfaces have been provided for simple use of everyday components.
|
||||
These input device component interfaces have been provided for simple use of
|
||||
everyday components.
|
||||
|
||||
Components must be wired up correctly before used in code.
|
||||
|
||||
*Note all GPIO pin numbers use BCM numbering. See the [notes](notes.md) page for more information.*
|
||||
*Note all GPIO pin numbers use BCM numbering. See the [notes](notes.md) page
|
||||
for more information.*
|
||||
|
||||
## Button
|
||||
|
||||
@@ -22,13 +24,16 @@ Ensure the `Button` class is imported at the top of the file:
|
||||
from gpiozero import Button
|
||||
```
|
||||
|
||||
Create a `Button` object by passing in the pin number the button is connected to:
|
||||
Create a `Button` object by passing in the pin number the button is connected
|
||||
to:
|
||||
|
||||
```python
|
||||
button = Button(2)
|
||||
```
|
||||
|
||||
The default behaviour is to set the *pull* state of the button to *up*. To change this behaviour, set the `pull_up` argument to `False` when creating your `Button` object.
|
||||
The default behaviour is to set the *pull* state of the button to *up*. To
|
||||
change this behaviour, set the `pull_up` argument to `False` when creating your
|
||||
`Button` object.
|
||||
|
||||
```python
|
||||
button = Button(pin=2, pull_up=False)
|
||||
@@ -67,7 +72,8 @@ Ensure the `MotionSensor` class is imported at the top of the file:
|
||||
from gpiozero import MotionSensor
|
||||
```
|
||||
|
||||
Create a `MotionSensor` object by passing in the pin number the sensor is connected to:
|
||||
Create a `MotionSensor` object by passing in the pin number the sensor is
|
||||
connected to:
|
||||
|
||||
```python
|
||||
pir = MotionSensor(3)
|
||||
@@ -97,7 +103,8 @@ Ensure the `LightSensor` class is imported at the top of the file:
|
||||
from gpiozero import LightSensor
|
||||
```
|
||||
|
||||
Create a `LightSensor` object by passing in the pin number the sensor is connected to:
|
||||
Create a `LightSensor` object by passing in the pin number the sensor is
|
||||
connected to:
|
||||
|
||||
```python
|
||||
light = LightSensor(4)
|
||||
@@ -145,7 +152,8 @@ temp = TemperatureSensor()
|
||||
|
||||
MCP3008 ADC (Analogue-to-Digital converter).
|
||||
|
||||
The MCP3008 chip provides access to up to 8 analogue inputs, such as potentiometers, and read their values in digital form.
|
||||
The MCP3008 chip provides access to up to 8 analogue inputs, such as
|
||||
potentiometers, and read their values in digital form.
|
||||
|
||||
### Wiring
|
||||
|
||||
@@ -166,7 +174,9 @@ with MCP3008() as pot:
|
||||
print(pot.read())
|
||||
```
|
||||
|
||||
It is possible to specify the `bus`, the `device` and the `channel` you wish to access. The previous example used the default value of `0` for each of these. To specify them, pass them in as arguments:
|
||||
It is possible to specify the `bus`, the `device` and the `channel` you wish to
|
||||
access. The previous example used the default value of `0` for each of these.
|
||||
To specify them, pass them in as arguments:
|
||||
|
||||
```python
|
||||
with MCP3008(bus=1, device=1, channel=4) as pot:
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
1. **BCM pin numbering**
|
||||
|
||||
This library uses BCM pin numbering for the GPIO pins, as opposed to BOARD. Unlike the `RPi.GPIO` library, it is not configurable.
|
||||
This library uses Broadcom (BCM) pin numbering for the GPIO pins, as
|
||||
opposed to BOARD. Unlike the `RPi.GPIO` library, this is not configurable.
|
||||
|
||||
Any pin marked `GPIO` can be used for generic components.
|
||||
|
||||
@@ -36,11 +37,11 @@
|
||||
- *5V = 5 Volts*
|
||||
- *DNC = Do not connect (special use pins)*
|
||||
|
||||
1. **Wiring**
|
||||
2. **Wiring**
|
||||
|
||||
All components must be wired up correctly before using with this library.
|
||||
|
||||
1. **Keep your program alive with `signal.pause`**
|
||||
3. **Keep your program alive with `signal.pause`**
|
||||
|
||||
The following program looks like it should turn an LED on:
|
||||
|
||||
@@ -52,9 +53,12 @@
|
||||
led.on()
|
||||
```
|
||||
|
||||
And it does, if you're using the Python shell, IPython shell or IDLE shell, but if you saved this program as a Python file and ran it, it would flash on for a moment then the program would end and it would turn off.
|
||||
And it does, if you're using the Python shell, IPython shell or IDLE shell,
|
||||
but if you saved this program as a Python file and ran it, it would flash
|
||||
on for a moment then the program would end and it would turn off.
|
||||
|
||||
The following file includes an intentional `pause` to keep the program alive:
|
||||
The following file includes an intentional `pause` to keep the program
|
||||
alive:
|
||||
|
||||
```python
|
||||
from gpiozero import LED
|
||||
@@ -67,9 +71,11 @@
|
||||
pause()
|
||||
```
|
||||
|
||||
Now running the program will stay running, leaving the LED on, until it is forced to quit.
|
||||
Now running the program will stay running, leaving the LED on, until it is
|
||||
forced to quit.
|
||||
|
||||
Similarly, when setting up callbacks on button presses or other input devices, the program needs to be running for the events to be detected:
|
||||
Similarly, when setting up callbacks on button presses or other input
|
||||
devices, the program needs to be running for the events to be detected:
|
||||
|
||||
```python
|
||||
from gpiozero import Button
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
# Output Devices
|
||||
|
||||
These output device component interfaces have been provided for simple use of everyday components.
|
||||
These output device component interfaces have been provided for simple use of
|
||||
everyday components.
|
||||
|
||||
Components must be wired up correctly before used in code.
|
||||
|
||||
*Note all GPIO pin numbers use BCM numbering. See the [notes](notes.md) page for more information.*
|
||||
*Note all GPIO pin numbers use BCM numbering. See the [notes](notes.md) page
|
||||
for more information.*
|
||||
|
||||
## LED
|
||||
|
||||
|
||||
Reference in New Issue
Block a user