Update docs

This commit is contained in:
Ben Nuttall
2015-10-25 18:54:20 +00:00
parent fe16149b12
commit af2bf9325c
2 changed files with 33 additions and 16 deletions

View File

@@ -209,24 +209,14 @@ None
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` | | | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` | | | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` | | | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
| `lights_on()` | Turn all three LEDs on. | None |
| `lights_off()` | Turn all three LEDs off. | None |
| `toggle_lights()` | Toggle all the board's LEDs. For each LED, if it's on, turn it off; if it's off, turn it on. | None |
| `blink_lights()` | Make the board's LEDs turn on and off repeatedly. | `on_time` - The amount of time (in seconds) for the LED to be on each iteration. Default: `1` |
| | | `off_time` - The amount of time (in seconds) for the LED to be off each iteration. Default: `1` |
| | | `n` - The number of iterations. `None` means infinite. Default: `None` |
| | | `background` - If True, start a background thread to continue blinking and return immediately. If False, only return when the blink is finished (warning: the default value of n will result in this method never returning). Default: `True` |
#### Properties #### Properties
| Property | Description | Type | | Property | Description | Type |
| -------- | ----------- | ---- | | -------- | ----------- | ---- |
| `red` | Direct access to the red light as a single `LED` object. | LED | | `lights` | Access to the three LEDs as a `TrafficLights` object. | TrafficLights |
| `amber` | Direct access to the amber light as a single `LED` object. | LED |
| `green` | Direct access to the green light as a single `LED` object. | LED |
| `buzzer` | Direct access to the buzzer as a single `Buzzer` object. | LED | | `buzzer` | Direct access to the buzzer as a single `Buzzer` object. | LED |
| `button` | Direct access to the button as a single `Button` object. | LED | | `button` | Direct access to the button as a single `Button` object. | LED |
| `leds` | A collection of LEDs to access each one individually, or to iterate over them in sequence. | Tuple |
| `all` | A collection of the board's output components to access each one individually, or to iterate over them in sequence. | Tuple | | `all` | A collection of the board's output components to access each one individually, or to iterate over them in sequence. | Tuple |
## Traffic HAT ## Traffic HAT

View File

@@ -25,10 +25,12 @@ Alternatively:
```python ```python
from gpiozero import LED from gpiozero import LED
from signal import pause
red = LED(2) red = LED(2)
red.blink() red.blink()
pause()
``` ```
## Button ## Button
@@ -40,10 +42,11 @@ from gpiozero import Button
button = Button(4) button = Button(4)
if button.is_active: while True:
print("Button is pressed") if button.is_pressed:
else: print("Button is pressed")
print("Button is not pressed") else:
print("Button is not pressed")
``` ```
Wait for a button to be pressed before continuing: Wait for a button to be pressed before continuing:
@@ -61,6 +64,7 @@ Run a function every time the button is pressed:
```python ```python
from gpiozero import Button from gpiozero import Button
from signal import pause
def say_hello(): def say_hello():
print("Hello!") print("Hello!")
@@ -68,6 +72,24 @@ def say_hello():
button = Button(4) button = Button(4)
button.when_pressed = say_hello button.when_pressed = say_hello
pause()
```
## Button controlled LED
Turn on an LED when a button is pressed:
```python
from gpiozero import LED, Button
from signal import pause
led = LED(2)
button = Button(3)
button.when_pressed = led.on
button.when_released = led.off
pause()
``` ```
## Traffic Lights ## Traffic Lights
@@ -147,6 +169,11 @@ with PiCamera() as camera:
frame += 1 frame += 1
``` ```
See
[Push Button Stop
Motion](https://www.raspberrypi.org/learning/quick-reaction-game/) for a full
resource.
## Reaction Game ## Reaction Game
When you see the light come on, the first person to press their button wins! When you see the light come on, the first person to press their button wins!
@@ -359,7 +386,7 @@ from time import sleep
robot = Robot(left=(4, 14), right=(17, 18)) robot = Robot(left=(4, 14), right=(17, 18))
for i in range(4): for i in range(4):
robot.forwards() robot.forward()
sleep(10) sleep(10)
robot.right() robot.right()
sleep(1) sleep(1)