Can't get debounce to work.. - Raspberry Pi Forums
hi all,
first post on forum - i'm finding useful! i'm little stuck @ moment though.
i'm building wifi radio use on ward of children's hospital. i've got code work pick audio stream, i'm having problem getting debounce work buttons. when press button start mplayer, launch several instances of it. same true when press button stop process.
i'm using python 2.7. got ideas?
cheers.
stewart
first post on forum - i'm finding useful! i'm little stuck @ moment though.
i'm building wifi radio use on ward of children's hospital. i've got code work pick audio stream, i'm having problem getting debounce work buttons. when press button start mplayer, launch several instances of it. same true when press button stop process.
i'm using python 2.7. got ideas?
cheers.
stewart
code: select all
# import global functions import os import time import rpi.gpio gpio # set gpio mode gpio.setmode(gpio.bcm) # clean gpio , supress warnings gpio.cleanup() gpio.setwarnings(false) # setup gpio input gpio.setup(17,gpio.in,pull_up_down=gpio.pud_up) gpio.setup(22,gpio.in,pull_up_down=gpio.pud_up) # define variable audio stream stream = 'http://www.streamingserver.com/audiostream' # define function button detection - gpio 17 def switch17(n): os.system('mplayer -slave -input file=/home/pi/mplayer-control ' +stream) time.sleep(0.5) # define function button detection - gpio 22 def switch22(n): os.system('echo "stop" >/home/pi/mplayer-control') # button detection gpio.add_event_detect(17,gpio.falling,callback=switch17,bouncetime=1000) gpio.add_event_detect(22,gpio.falling,callback=switch22,bouncetime=1000) # function creates endless loop # nothing, in order button detection work try: flag = 0 while flag == 0: if flag == 1: flag = 0 else: flag = 0 except keyboardinterrupt: gpio.cleanup()
first thing sprang mind was. version of rpi.gpio running?
debounce introduced couple of weeks ago 0.5.2a. if have older that, debounce won't work (but expect error out).
gpio.cleanup() nothing @ top of script. cleans ports have been opened or changed script.
debounce introduced couple of weeks ago 0.5.2a. if have older that, debounce won't work (but expect error out).
gpio.cleanup() nothing @ top of script. cleans ports have been opened or changed script.
raspberrypi
Comments
Post a Comment