gpio - Controlling a relay with a momentary button in Python -


i able control relay momentary button code below:

#!/usr/bin/env python  import rpi.gpio gpio import time  gpio.setmode(gpio.bcm) gpio.setup(17, gpio.in, gpio.pud_up) gpio.setup(4, gpio.out)  gpio.output(4, gpio.high)  def callback_func(pin):     if gpio.input(17):         gpio.output(4, gpio.high)     else:         gpio.output(4, gpio.low)  gpio.add_event_detect(17, gpio.both, callback=callback_func, bouncetime=200)  def main():     while true:         print "not blocking! you're free other stuff here"         time.sleep(5)  if __name__ == "__main__":     main() 

this, seems once. once release botton , try again, regardless how time in between won't work. there specific reason run once?

preferably want able keep using button without having stop python script , restarting one-time button relay action.

thanks!

removing bouncetime completly fixed issue. so:

gpio.add_event_detect(17, gpio.both, callback=callback_func, bouncetime=200) 

to

gpio.add_event_detect(17, gpio.both, callback=callback_func) 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -