#!/usr/bin/python3
# http://razzpisampler.oreilly.com/ch07.html
# http://web.archive.org/web/20160305001215/http://razzpisampler.oreilly.com/ch07.html
from RPi import GPIO
import time
import subprocess

button_pin = 23

def on_button(pin):
    print("Button pressed", pin)

GPIO.setmode(GPIO.BCM)

GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    pin = GPIO.wait_for_edge(button_pin, GPIO.FALLING)
    if pin == button_pin:
        subprocess.check_call(["/bin/systemctl", "halt"])
