def loop(): GPIO.add_event_detect(ButtonPin, GPIO.FALLING, callback=buttonPress) while True: pass # When running directly, make sure to cleanup GPIO