#!/usr/bin/python import RPi.GPIO as GPIO import sys import time # Init GPIOs GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Interrupt routine, beeing called, when interrupt happens def interrupt_routine(callback): print "Interrupt triggered!" #Add your own code here # Init Interrupt-Callback-Function --> register the interrupt trigger GPIO.add_event_detect(25, GPIO.FALLING, callback=interrupt_routine) # Simple init to abort program later with Ctrl+C in an exception runProgram = True #Run usual script while runProgram: try: print time.strftime("%d.%m.%Y %H:%M:%S"), "Just doing nothing, awaiting an interrupt..." #Put your main program's code in here # Sleeping 5 seconds top make it readable time.sleep(5) except: print "Exception thrown -> Abort" runProgram = False # Final cleanup GPIO.cleanup()