Code: Select all
#-*- coding: UTF-8 -*
import os
import sys
import time
import datetime
import subprocess
import RPi.GPIO as GPIO
def snap(channel):
print "pulsante premuto"
subprocess.call("python /home/registra.py", shell=True)
GPIO.setmode(GPIO.BCM)
button = 7
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
'''
button_last = GPIO.input(button)
while True:
button_now = GPIO.input(button)
if button_now != button_last and button_now == GPIO.LOW:
snap()
button_last = button_now
time.sleep(0.01)
'''
GPIO.add_event_detect(button, GPIO.FALLING, callback=snap, bouncetime=300)
while True:
try:
time.sleep(1.0)
except KeyboardInterrupt:
print("except..")
break
GPIO.remove_event_detect(button)
GPIO.cleanup()
print('end of script.')