so I have the following code that turns an LED on when a button is pressed. No problem there. What I need to be able to do is turn the LED off when the button is pressed again.
I've been on this for a couple of days and cant seem to fathom it out.
I'm in the process of building a camera and this issue is the basis for starting/stopping the motion detection script (which will use the LED as an indicator).
Code: Select all
import RPi.GPIO as GPIO
# Define a function to keep script running
def loop():
raw_input()
# Define a function to run when an interrupt is called
def LEDON(pin):
GPIO.output(25, True)
GPIO.setmode(GPIO.BCM) #Set pin numbering to GPIO numbering
GPIO.setup(24, GPIO.IN) # Set up GPIO 24 as an input (button)
GPIO.setup(25, GPIO.OUT) # Set GPIO 25 as an output (LED)
GPIO.output(25, False)
GPIO.add_event_detect(24, GPIO.RISING, callback=LEDON, bouncetime=200)
loop() # Run the loop function to keep script runningThis is the schematic for the little circuit: