Read Time:20 Second
import RPi.GPIO as GPIO from time import sleep PIN18 = 12 PIN25 = 22 GPIO.setmode(GPIO.BOARD) GPIO.setup(PIN25, GPIO.IN) GPIO.setup(PIN18, GPIO.OUT) LEDON = False while 1: try: if GPIO.input(PIN25): if LEDON == True: print "-- PIN25 ON" LEDON = False GPIO.output(PIN18, False) else: print "-- PIN25 OFF" LEDON = True GPIO.output(PIN18, True) sleep(1) except KeyboardInterrupt: GPIO.cleanup()