Add Shutdown button example to recipes, close #325

This commit is contained in:
Ben Nuttall
2016-05-29 20:19:09 +01:00
parent 35d9228843
commit 963b962867

View File

@@ -239,6 +239,25 @@ another to capture::
pause()
Shutdown button
===============
The :class:`Button` class also provides the ability to run a function when the
button has been held for a given length of time. This example will shut down
the Raspberry Pi when the button is held for 2 seconds::
from gpiozero import Button
from subprocess import check_call
from signal import pause
def shutdown():
check_call(['sudo', 'poweroff'])
shutdown_btn = Button(17, hold_time=2)
shutdown_btn.when_held = shutdown
pause()
LEDBoard
========