import time import RPi.GPIO as GPIO BUCKET_PIN = 7 GPIO.setmode(GPIO.BOARD) GPIO.setup(BUCKET_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) def bucket_back(channel): print("Back") GPIO.add_event_detect(BUCKET_PIN, GPIO.RISING, callback=bucket_back) try: while True: time.sleep(0.1) except KeyboardInterrupt: pass GPIO.cleanup()