The following script is designed to turn on an LED whilst a button is in a depressed state and turn the LED off when the button is released. When run however the LED comes on whether or not the button is held down and stays on regardless. I've tried all day to find out what the problem is but to no avail. Can anybody help me identify what might be the problem? Thanks!
Code: Select all
import RPi.GPIO as GPIO import time import os from time import sleep GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(10,GPIO.OUT) print "LED ON" GPIO.output(10,GPIO.HIGH) while True: input_state = GPIO.input(7) if input_state == True: print "LED OFF" GPIO.output(10,GPIO.LOW) time.sleep(1) exit() message = input("Press enter to quit\n\n") GPIO.cleanup()