mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add Shutdown button example to recipes, close #325
This commit is contained in:
@@ -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
|
||||
========
|
||||
|
||||
|
||||
Reference in New Issue
Block a user