diff --git a/docs/boards.md b/docs/boards.md index 3c5b8d2..d2213c2 100644 --- a/docs/boards.md +++ b/docs/boards.md @@ -209,24 +209,14 @@ None | | | `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` | -| `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 | Property | Description | Type | | -------- | ----------- | ---- | -| `red` | Direct access to the red light as a single `LED` object. | LED | -| `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 | +| `lights` | Access to the three LEDs as a `TrafficLights` object. | TrafficLights | | `buzzer` | Direct access to the buzzer as a single `Buzzer` 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 | ## Traffic HAT diff --git a/docs/recipes.md b/docs/recipes.md index 0276679..9a386a7 100644 --- a/docs/recipes.md +++ b/docs/recipes.md @@ -25,10 +25,12 @@ Alternatively: ```python from gpiozero import LED +from signal import pause red = LED(2) red.blink() +pause() ``` ## Button @@ -40,10 +42,11 @@ from gpiozero import Button button = Button(4) -if button.is_active: - print("Button is pressed") -else: - print("Button is not pressed") +while True: + if button.is_pressed: + print("Button is pressed") + else: + print("Button is not pressed") ``` Wait for a button to be pressed before continuing: @@ -61,6 +64,7 @@ Run a function every time the button is pressed: ```python from gpiozero import Button +from signal import pause def say_hello(): print("Hello!") @@ -68,6 +72,24 @@ def say_hello(): button = Button(4) 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 @@ -147,6 +169,11 @@ with PiCamera() as camera: frame += 1 ``` +See +[Push Button Stop +Motion](https://www.raspberrypi.org/learning/quick-reaction-game/) for a full +resource. + ## Reaction Game 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)) for i in range(4): - robot.forwards() + robot.forward() sleep(10) robot.right() sleep(1)