mirror of
https://github.com/kevinveenbirkenbach/raspberry-pi-tools.git
synced 2024-11-26 03:44:44 +01:00
Shutdownbutton-Script hinzugefuegt
This commit is contained in:
parent
4688da3647
commit
861d54ab42
38
shutdownbutton.py
Normal file
38
shutdownbutton.py
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/python
|
||||
# Simple script for shutting down the raspberry Pi at the press of a button.
|
||||
# by Inderpreet Singh
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import os
|
||||
|
||||
# Use the Broadcom SOC Pin numbers
|
||||
# Setup the Pin with Internal pullups enabled and PIN in reading mode.
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||
|
||||
# Our function on what to do when the button is pressed
|
||||
def Shutdown(channel):
|
||||
os.system("sudo shutdown -h now")
|
||||
|
||||
# Add our function to execute when the button pressed event happens
|
||||
GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
|
||||
|
||||
# Now wait!
|
||||
while 1:
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
#Borougth by https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user