Last active
September 6, 2017 07:17
-
-
Save takakabe/b85a23b18cbfccf5f0b4d727536eb8aa to your computer and use it in GitHub Desktop.
RaspberryPi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import RPi.GPIO as GPIO | |
from time import sleep | |
import subprocess | |
###################### | |
# 関数 my_callback | |
###################### | |
def my_callback(channnel): | |
subprocess.Popen(['sudo','shutdown']) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) | |
# GPIO.RISING スイッチがおされたとき | |
# bouncetime=300 一度イベントを検出したら300ミリ秒が次のイベントを検出しないよう設定 | |
GPIO.add_event_detect(14, GPIO.RISING, callback=my_callback, bouncetime=300) | |
# プログラムが終了しないように無限ループさせている | |
try: | |
while True: | |
sleep(0.01) | |
except KeyboardInterrupt: | |
pass | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment