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