mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-12-08 20:39:01 +00:00
@@ -15,13 +15,15 @@ The latest release is **v0.7.0 beta 2** released on 9th October 2015.
|
|||||||
With very little code, you can quickly get going connecting your physical
|
With very little code, you can quickly get going connecting your physical
|
||||||
components together:
|
components together:
|
||||||
|
|
||||||
from gpiozero import LED, Button
|
```python
|
||||||
|
from gpiozero import LED, Button
|
||||||
|
|
||||||
led = LED(2)
|
led = LED(2)
|
||||||
button = Button(3)
|
button = Button(3)
|
||||||
|
|
||||||
button.when_pressed = led.on
|
button.when_pressed = led.on
|
||||||
button.when_released = led.off
|
button.when_released = led.off
|
||||||
|
```
|
||||||
|
|
||||||
The library includes interfaces to many simple everyday components, as well as
|
The library includes interfaces to many simple everyday components, as well as
|
||||||
some more complex things like sensors, analogue-to-digital converters, full
|
some more complex things like sensors, analogue-to-digital converters, full
|
||||||
|
|||||||
@@ -45,13 +45,10 @@
|
|||||||
|
|
||||||
The following program looks like it should turn an LED on:
|
The following program looks like it should turn an LED on:
|
||||||
|
|
||||||
```python
|
|
||||||
from gpiozero import led
|
from gpiozero import led
|
||||||
|
|
||||||
led = LED(2)
|
led = LED(2)
|
||||||
|
|
||||||
led.on()
|
led.on()
|
||||||
```
|
|
||||||
|
|
||||||
And it does, if you're using the Python shell, IPython shell or IDLE shell,
|
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
|
but if you saved this program as a Python file and ran it, it would flash
|
||||||
@@ -60,16 +57,12 @@
|
|||||||
The following file includes an intentional `pause` to keep the program
|
The following file includes an intentional `pause` to keep the program
|
||||||
alive:
|
alive:
|
||||||
|
|
||||||
```python
|
|
||||||
from gpiozero import LED
|
from gpiozero import LED
|
||||||
from signal import pause
|
from signal import pause
|
||||||
|
|
||||||
led = LED(2)
|
led = LED(2)
|
||||||
|
|
||||||
led.on()
|
led.on()
|
||||||
|
|
||||||
pause()
|
pause()
|
||||||
```
|
|
||||||
|
|
||||||
Now running the program will stay running, leaving the LED on, until it is
|
Now running the program will stay running, leaving the LED on, until it is
|
||||||
forced to quit.
|
forced to quit.
|
||||||
@@ -77,13 +70,9 @@
|
|||||||
Similarly, when setting up callbacks on button presses or other input
|
Similarly, when setting up callbacks on button presses or other input
|
||||||
devices, the program needs to be running for the events to be detected:
|
devices, the program needs to be running for the events to be detected:
|
||||||
|
|
||||||
```python
|
|
||||||
from gpiozero import Button
|
from gpiozero import Button
|
||||||
from signal import pause
|
from signal import pause
|
||||||
|
|
||||||
button = Button(2)
|
button = Button(2)
|
||||||
|
|
||||||
button.when_pressed = lambda: print("Button was pressed!")
|
button.when_pressed = lambda: print("Button was pressed!")
|
||||||
|
|
||||||
pause()
|
pause()
|
||||||
```
|
|
||||||
|
|||||||
Reference in New Issue
Block a user