@@ -30,6 +30,7 @@ from signal import pause
3030red = LED(2 )
3131
3232red.blink()
33+
3334pause()
3435```
3536
@@ -72,6 +73,7 @@ def say_hello():
7273button = Button(4 )
7374
7475button.when_pressed = say_hello
76+
7577pause()
7678```
7779
@@ -215,14 +217,10 @@ Each button plays a different sound!
215217from gpiozero import Button
216218import pygame.mixer
217219from pygame.mixer import Sound
220+ from signal import pause
218221
219222pygame.mixer.init()
220223
221- def play (pin ):
222- sound = sound_pins[pin]
223- print (" playing note from pin %s " % pin)
224- sound.play()
225-
226224sound_pins = {
227225 2 : Sound(" samples/drum_tom_mid_hard.wav" ),
228226 3 : Sound(" samples/drum_cymbal_open.wav" ),
@@ -232,6 +230,8 @@ buttons = [Button(pin) for pin in sound_pins]
232230for button in buttons:
233231 sound = sound_pins[button.pin]
234232 button.when_pressed = sound.play
233+
234+ pause()
235235```
236236
237237See [ GPIO Music Box] ( https://www.raspberrypi.org/learning/gpio-music-box/ )
@@ -245,28 +245,35 @@ FishDish:
245245
246246``` python
247247from gpiozero import FishDish
248+ from signal import pause
248249
249250fish = FishDish()
250251
251252fish.button.when_pressed = fish.on
252253fish.button.when_released = fish.off
254+
255+ pause()
253256```
254257
255258Ryanteck Traffic HAT:
256259
257260``` python
258261from gpiozero import TrafficHat
262+ from signal import pause
259263
260264th = TrafficHat()
261265
262266th.button.when_pressed = th.on
263267th.button.when_released = th.off
268+
269+ pause()
264270```
265271
266272Using components:
267273
268274``` python
269275from gpiozero import LED , Buzzer, Button
276+ from signal import pause
270277
271278button = Button(2 )
272279buzzer = Buzzer(3 )
@@ -286,6 +293,8 @@ def things_off():
286293
287294button.when_pressed = things_on
288295button.when_released = things_off
296+
297+ pause()
289298```
290299
291300## RGB LED
@@ -322,12 +331,15 @@ Light an LED when motion is detected:
322331
323332``` python
324333from gpiozero import MotionSensor, LED
334+ from signal import pause
325335
326336pir = MotionSensor(5 )
327337led = LED(16 )
328338
329339pir.when_motion = led.on
330340pir.when_no_motion = led.off
341+
342+ pause()
331343```
332344
333345## Light Sensor
@@ -350,12 +362,15 @@ Run a function when the light changes:
350362
351363``` python
352364from gpiozero import LightSensor, LED
365+ from signal import pause
353366
354367sensor = LightSensor(18 )
355368led = LED(16 )
356369
357370sensor.when_dark = led.on
358371sensor.when_light = led.off
372+
373+ pause()
359374```
360375
361376## Motors
@@ -456,12 +471,15 @@ Make a robot drive forward when it detects motion:
456471
457472``` python
458473from gpiozero import Robot, MotionSensor
474+ from signal import pause
459475
460476robot = Robot(left = (4 , 14 ), right = (17 , 18 ))
461477pir = MotionSensor(5 )
462478
463479pir.when_motion = robot.forward
464480pir.when_no_motion = robot.stop
481+
482+ pause()
465483```
466484
467485## Potentiometer
@@ -510,4 +528,6 @@ blue_pot = MCP3008(channel=2)
510528led.red.source = red_pot.values
511529led.green.source = green_pot.values
512530led.blue.source = blue_pot.values
531+
532+ pause()
513533```
0 commit comments