Last active
September 3, 2017 12:37
-
-
Save takakabe/ff9f2b0a82fcc953cd5cb6e08d7f0a95 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): | |
filename="wawawa.jpg" | |
subprocess.Popen(['raspistill','-o',filename,'-t','1']) | |
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