import RPi.GPIO as GPIO import time led = 20 in6 = 6 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(led,GPIO.OUT) GPIO.setup(in6,GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(led,GPIO.LOW) print "CTRL+C = STOP program" try: while True: if GPIO.input(in6) == 0: GPIO.output(led,GPIO.HIGH) else: GPIO.output(led,GPIO.LOW) except KeyboardInterrupt: GPIO.cleanup() # must be executed before program stop