Python RPi.GPIO 模块,FALLING 实例源码

我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用RPi.GPIO.FALLING

项目:dronestorm    作者:Stanford-BIS    | 项目源码 | 文件源码
def measureDistance_HCSRO4(TRIG_ID, ECHO_ID):
    GPIO.output(TRIG_ID, True)
    time.sleep(0.00001)
    GPIO.output(TRIG_ID, False)

    edge_detect = GPIO.wait_for_edge(ECHO_ID, GPIO.RISING, timeout = 100)

    if edge_detect is not None:
        pulse_start = time.time()
    else: return MAX_DIST

    edge_detect = GPIO.wait_for_edge(ECHO_ID, GPIO.FALLING, timeout = 100)

    if edge_detect is not None:
        pulse_end = time.time()
    else: return MAX_DIST

    pulse_duration = pulse_end - pulse_start
    distance = round(pulse_duration * 17150, 2)

    return distance
项目:AlexaPiDEPRECATED    作者:alexa-pi    | 项目源码 | 文件源码
def start():
    last = GPIO.input(button)
    while True:
        val = GPIO.input(button)
        GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed
        GPIO.output(lights[1], GPIO.HIGH)
        inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device)
        inp.setchannels(1)
        inp.setrate(16000)
        inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
        inp.setperiodsize(500)
        audio = ""
        while(GPIO.input(button)==0): # we keep recording while the button is pressed
            l, data = inp.read()
            if l:
                audio += data
        rf = open(path+'recording.wav', 'w')
        rf.write(audio)
        rf.close()
        inp = None
        alexa()
项目:AlexaPi    作者:HighTeckMan    | 项目源码 | 文件源码
def start():
    last = GPIO.input(button)
    while True:
        val = GPIO.input(button)
        GPIO.wait_for_edge(button, GPIO.FALLING) # we wait for the button to be pressed
        GPIO.output(lights[1], GPIO.HIGH)
        inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device)
        inp.setchannels(1)
        inp.setrate(16000)
        inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
        inp.setperiodsize(500)
        audio = ""
        while(GPIO.input(button)==0): # we keep recording while the button is pressed
            l, data = inp.read()
            if l:
                audio += data
        rf = open(path+'recording.wav', 'w')
        rf.write(audio)
        rf.close()
        inp = None
        alexa()
项目:kalliope    作者:kalliope-project    | 项目源码 | 文件源码
def init_gpio(self, rpi_settings):
        """
        Initialize GPIO pin to a default value. Leds are off by default
        Mute button is set as an input
        :param rpi_settings: RpiSettings object
        """
        # All led are off by default
        if self.rpi_settings.pin_led_muted:
            GPIO.setup(rpi_settings.pin_led_muted, GPIO.OUT, initial=GPIO.LOW)
        if self.rpi_settings.pin_led_started:
            GPIO.setup(rpi_settings.pin_led_started, GPIO.OUT, initial=GPIO.LOW)
        if self.rpi_settings.pin_led_listening:
            GPIO.setup(rpi_settings.pin_led_listening, GPIO.OUT, initial=GPIO.LOW)
        if self.rpi_settings.pin_led_talking:
            GPIO.setup(rpi_settings.pin_led_talking, GPIO.OUT, initial=GPIO.LOW)

        # MUTE button
        if self.rpi_settings.pin_mute_button:
            GPIO.setup(rpi_settings.pin_mute_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(rpi_settings.pin_mute_button, GPIO.FALLING,
                                  callback=self.switch_kalliope_mute_led,
                                  bouncetime=500)
项目:BlogCode    作者:yaptb    | 项目源码 | 文件源码
def event_loop(self):

            count =0

            keys_per_rev=5
            key_press_delay=0.05
            inter_key_delay=0.1
            last_time=0
            current_time=0

            GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=100) 

            while True:

                if(self.hitCount >0):
                    count+=1
                    print "Hit ",count
                    self.hitCount-=1

                time.sleep(0.01)
项目:RaspberryPi-projects    作者:gary-dalton    | 项目源码 | 文件源码
def button_press_switch(channel):
    global button_status
    GPIO.remove_event_detect(channel)
    logging.info('Button pressed')
    pressed_time = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_time
    pressed_time = dif.seconds
    if pressed_time > 6:
        shutdown()
        button_status = BUTTON_SHUTDOWN
    elif pressed_time > 2:
        button_status = BUTTON_MONITOR_SWITCH
    else:
        button_status = BUTTON_SENSOR_SWITCH
    logging.info("Button status = %s", button_status)
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=button_press_switch, bouncetime=200)


# Run cleanup routines
项目:RaspberryPi-projects    作者:gary-dalton    | 项目源码 | 文件源码
def shutdown(channel):
    """
    Calls system shutdown after a button press of more than 2 seconds
    """
    GPIO.remove_event_detect(channel)
    pressed_timestamp = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_timestamp
    pressed_time = dif.seconds
    logging.debug('Pressed time = %s', pressed_time)
    if pressed_time > 2:
        logging.info('Button initiated shutdown')
        os.system("sudo shutdown -h now")
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=shutdown, bouncetime=200)

# Add button pressed event detects
项目:RaspberryPi-projects    作者:gary-dalton    | 项目源码 | 文件源码
def shutdown(channel): # Change to lowercase function name
    # Modify function to require the shutdown button to be pressed and held
    # for at least 2 seconds before shutting down.
    GPIO.remove_event_detect(channel)
    pressed_time = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_time
    pressed_time = dif.seconds
    logging.debug('Pressed time = %s', pressed_time)
    if pressed_time > 2:
        pass
        #os.system("sudo shutdown -h now")
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=shutdown, bouncetime=200)
##

##
项目:RaspberryPi-projects    作者:gary-dalton    | 项目源码 | 文件源码
def button_press_switch(channel):
    GPIO. remove_event_detect(channel)
    print('Button pressed')
    pressed_time = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_time
    pressed_time = dif.seconds
    if pressed_time < 2:
        button_status = 1
    elif pressed_time < 6:
        button_status = 2
    else:
        button_status = 4
    print(button_status)
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=button_press_switch,  bouncetime=200)
##

##
项目:Venenfinder    作者:Myrijam    | 项目源码 | 文件源码
def __init__(self,pinA,pinB,callback):
      self.pinA = pinA
      self.pinB = pinB
      #self.button = button
      self.callback = callback
      GPIO.setmode(GPIO.BCM)
      # The following lines enable the internal pull-up resistors
      # on version 2 (latest) boards
      GPIO.setwarnings(False)
      GPIO.setup(self.pinA, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(self.pinB, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      #GPIO.setup(self.button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      # For version 1 (old) boards comment out the above four lines
      # and un-comment the following 3 lines
      #GPIO.setup(self.pinA, GPIO.IN)
      #GPIO.setup(self.pinB, GPIO.IN)
      #GPIO.setup(self.button, GPIO.IN)
      # Add event detection to the GPIO inputs
      GPIO.add_event_detect(self.pinA, GPIO.FALLING, callback=self.switch_event)
      GPIO.add_event_detect(self.pinB, GPIO.FALLING, callback=self.switch_event)
      #GPIO.add_event_detect(self.button, GPIO.BOTH, callback=self.button_event, bouncetime=200)
      return


# Call back routine called by switch events
项目:RuneAudioLCDMod    作者:lukazgur    | 项目源码 | 文件源码
def __init__(self, button_pins, bounce_time):
        # Set bounce time
        self.bounce_time = bounce_time

        # Set buttons
        self.buttons = button_pins

        # Initialize display client
        self.display = False

        # We don't need warnings from GPIO
        GPIO.setwarnings(False)

        # Set button GPIO pins as inputs and enable interrupts
        for button in button_pins:
            if (button_pins[button] != False):
                GPIO.setup(button_pins[button], GPIO.IN, pull_up_down = GPIO.PUD_UP)
                GPIO.add_event_detect(button_pins[button], GPIO.FALLING, callback=self.button_pressed, bouncetime=self.bounce_time)

        # Initalize MPD
        self.mpd = False

    # Register MPD client to send it commands
项目:GBZ-Power-Monitor_BG    作者:Camble    | 项目源码 | 文件源码
def lowBattery(channel):
  #Checking for LED bounce for the duration of the battery Timeout
  for bounceSample in range(1, int(round(batteryTimeout / sampleRate))):
    time.sleep(sampleRate)

    if GPIO.input(batteryGPIO) is 1:
       break

  global playerFlag
  while playerFlag is 1:
    time.sleep(1)

  #If the LED is a solid for more than 10% of the timeout, we know that the battery is getting low.  Launch the Low Battery alert.
  if bounceSample > int(round(batteryTimeout / sampleRate * 0.1)):
    playerFlag = 1
    os.system("/usr/bin/omxplayer --no-osd --layer 999999 " + lowalertVideo + " --alpha 160;");
    playerFlag = 0

    #Discovered a bug with the Python GPIO library and threaded events.  Need to unbind and rebind after a System Call or the program will crash
    GPIO.remove_event_detect(batteryGPIO)
    GPIO.add_event_detect(batteryGPIO, GPIO.FALLING, callback=lowBattery, bouncetime=300)
项目:GBZ-Power-Monitor_BG    作者:Camble    | 项目源码 | 文件源码
def main():
  #if the Low Battery LED is active when the program launches, handle it
  if GPIO.input(batteryGPIO) is 0:
    lowBattery(batteryGPIO)

  #if the Power Switch is active when the program launches, handle it
  if GPIO.input(powerGPIO) is 1:
    powerSwitch(powerGPIO)

  #Add threaded event listeners for the Low Battery and Power Switch
  try:
    GPIO.remove_event_detect(batteryGPIO)
    GPIO.add_event_detect(batteryGPIO, GPIO.FALLING, callback=lowBattery, bouncetime=300)

    GPIO.remove_event_detect(powerGPIO)
    GPIO.add_event_detect(powerGPIO, GPIO.RISING, callback=powerSwitch, bouncetime=300)
  except KeyboardInterrupt:
    GPIO.cleanup()
项目:Webradio_v2    作者:Acer54    | 项目源码 | 文件源码
def __init__(self,pinA,pinB,button,callback, parent):
        self.pinA = pinA
        self.pinB = pinB
        self.button = button
        self.callback = callback
        self.parent = parent
        if self.pinA is not None and self.pinB is not None:
            GPIO.setmode(GPIO.BOARD)

            GPIO.setwarnings(False)
            GPIO.setup(self.pinA, GPIO.IN)
            GPIO.setup(self.pinB, GPIO.IN)
            GPIO.add_event_detect(self.pinA, GPIO.FALLING,
            callback=self.switch_event)
            GPIO.add_event_detect(self.pinB, GPIO.FALLING,
            callback=self.switch_event)

        if self.button is not None:
            GPIO.setup(self.button, GPIO.IN)
            GPIO.add_event_detect(self.button, GPIO.BOTH,
            callback=self.button_event, bouncetime=200)

        return
        # Call back routine called by switch events
项目:SunFounder_Super_Kit_V3.0_for_Raspberry_Pi    作者:sunfounder    | 项目源码 | 文件源码
def setup():
    global counter
    global Last_RoB_Status, Current_RoB_Status
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(RoAPin, GPIO.IN)
    GPIO.setup(RoBPin, GPIO.IN)
    GPIO.setup(RoSPin,GPIO.IN, pull_up_down=GPIO.PUD_UP)
    # Set up a falling edge detect to callback clear
    GPIO.add_event_detect(RoSPin, GPIO.FALLING, callback=clear)

    # Set up a counter as a global variable
    counter = 0
    Last_RoB_Status = 0
    Current_RoB_Status = 0

# Define a function to deal with rotary encoder
项目:Sample-Code    作者:meigrafd    | 项目源码 | 文件源码
def main():
    try:    
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(START_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        root = tk.Tk()
        root.overrideredirect(True)
        width, height = root.winfo_screenwidth(), root.winfo_screenheight()
        root.geometry('{0}x{1}+0+0'.format(width, height))
        root.wm_title('Stoppuhr')
        stopwatch = Stopwatch(LOG_FILENAME)
        GPIO.add_event_detect(START_PIN, GPIO.FALLING, stopwatch.start)
        stopwatch_ui = StopwatchUI(root, stopwatch)
        stopwatch_ui.pack()
        root.mainloop()
    finally:
        GPIO.cleanup()
项目:tipi    作者:jedimatt42    | 项目源码 | 文件源码
def __init__(self):
        self.__RESET = 26

        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

        GPIO.setup(self.__RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Do not proceed unless the reset signal has turned off
        # attempt to prevent restart storm in systemd

        print "waiting for reset to complete."
        while GPIO.input(self.__RESET) != 1:
            time.sleep(0.100)
            pass

        GPIO.add_event_detect(
            self.__RESET,
            GPIO.FALLING,
            callback=onReset,
            bouncetime=100)
        print "GPIO initialized."
项目:GBZ-Power-Monitor_PB    作者:Camble    | 项目源码 | 文件源码
def main():
  #if the Low Battery LED is active when the program launches, handle it
  if GPIO.input(batteryGPIO) is 0:
    lowBattery(batteryGPIO)

  #if the Power Switch is active when the program launches, handle it
  if GPIO.input(powerGPIO) is 0:
    powerSwitch(powerGPIO)

  #Add threaded event listeners for the Low Battery and Power Switch
  try:
    GPIO.remove_event_detect(batteryGPIO)
    GPIO.add_event_detect(batteryGPIO, GPIO.FALLING, callback=lowBattery, bouncetime=300)

    GPIO.remove_event_detect(powerGPIO)
    GPIO.add_event_detect(powerGPIO, GPIO.FALLING, callback=powerSwitch, bouncetime=300)
  except KeyboardInterrupt:
    GPIO.cleanup()
项目:raspi-photo-booth    作者:kriskbx    | 项目源码 | 文件源码
def loop():
    GPIO.add_event_detect(ButtonPin, GPIO.FALLING, callback=buttonPress)
    while True:
        pass

# When running directly, make sure to cleanup GPIO
项目:polapi-zero    作者:pierre-muth    | 项目源码 | 文件源码
def haltSystem():
    print 'Halt...'
    os.system("sudo halt")

# GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000)
项目:polapi-zero    作者:pierre-muth    | 项目源码 | 文件源码
def haltSystem():
    print 'Halt...'
    os.system("sudo halt")

# GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000)
项目:voicetools    作者:namco1992    | 项目源码 | 文件源码
def set_voice_sensor():
    GPIO.setup(GPIOConfig.VOICE_SENSOR, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(GPIOConfig.VOICE_SENSOR, GPIO.FALLING)
项目:voicetools    作者:namco1992    | 项目源码 | 文件源码
def loop():
    # ???
    handler = BaseHandler()
    try:
        while True:
            # ?????
            if GPIO.event_detected(GPIOConfig.VOICE_SENSOR):
                GPIO.remove_event_detect(GPIOConfig.VOICE_SENSOR)
                handler.worker()
                GPIO.add_event_detect(GPIOConfig.VOICE_SENSOR, GPIO.FALLING)
            time.sleep(0.5)
    except KeyboardInterrupt:
        pass
    GPIO.cleanup()
项目:pi-photo-booth    作者:gamblecd    | 项目源码 | 文件源码
def listen(self, callback):
        if not callback:
            callback = self.callback
        GPIO.add_event_detect(self.button_pin,
                              GPIO.FALLING,
                              callback=callback,
                              bouncetime=500)
项目:aiyprojects-raspbian    作者:google    | 项目源码 | 文件源码
def __init__(self, channel, polarity=GPIO.FALLING,
                 pull_up_down=GPIO.PUD_UP):
        super().__init__()

        self.channel = channel
        self.polarity = polarity

        if polarity not in [GPIO.FALLING, GPIO.RISING]:
            raise ValueError('polarity must be GPIO.FALLING or GPIO.RISING')

        self.expected_value = polarity == GPIO.RISING
        self.event_detect_added = False

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)
项目:aiyprojects-raspbian    作者:google    | 项目源码 | 文件源码
def __init__(self,
                 channel,
                 polarity=GPIO.FALLING,
                 pull_up_down=GPIO.PUD_UP,
                 debounce_time=0.08):
        """A simple GPIO-based button driver.

        This driver supports a simple GPIO-based button. It works by detecting
        edges on the given GPIO channel. Debouncing is automatic.

        Args:
          channel: the GPIO pin number to use (BCM mode)
          polarity: the GPIO polarity to detect; either GPIO.FALLING or
            GPIO.RISING.
          pull_up_down: whether the port should be pulled up or down; defaults to
            GPIO.PUD_UP.
          debounce_time: the time used in debouncing the button in seconds.
        """

        if polarity not in [GPIO.FALLING, GPIO.RISING]:
            raise ValueError(
                'polarity must be one of: GPIO.FALLING or GPIO.RISING')

        self.channel = int(channel)
        self.polarity = polarity
        self.expected_value = polarity == GPIO.RISING
        self.debounce_time = debounce_time

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)

        self.callback = None
项目:52-Weeks-of-Pi    作者:grantwinney    | 项目源码 | 文件源码
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup([R,G], GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.add_event_detect(BUTTON, GPIO.FALLING, fan_the_flame, 250)
项目:52-Weeks-of-Pi    作者:grantwinney    | 项目源码 | 文件源码
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LIGHTS, GPIO.OUT, initial=GPIO.LOW)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    for i in range(4):
        GPIO.add_event_detect(BUTTONS[i], GPIO.FALLING, verify_player_selection, 400 if use_sounds else 250)
项目:garage-butler    作者:gurumitts    | 项目源码 | 文件源码
def __init__(self):
        logging.getLogger('garage').info('Butler is starting...')
        logging.getLogger('garage').info('AWS: region=%s, topic=%s' % (REGION, TOPIC))
        self.camera = Camera()
        self.notify = Notify(self)
        GPIO.add_event_detect(button_pin, GPIO.FALLING, callback=self.door_check, bouncetime=1000)
        scheduler.start()
        scheduler.add_job(self.status_check, 'interval', minutes=1)
        self.last_notification = datetime.datetime.strptime('Jun 1 2005  1:00PM', '%b %d %Y %I:%M%p')
        self.last_status = GPIO.input(button_pin)
项目:delight-diploma-thesis    作者:alexpeits    | 项目源码 | 文件源码
def irqWait(self, timeout = 30000):
        # CHANGE: detect module name because wait_for_edge is not available in
        # other libraries
        if GPIO.__name__ != "Adafruit_BBIO.GPIO":
            return False

        # TODO: A race condition may occur here.
        if GPIO.input(self.irq_pin) == 0: # Pin is already down. Packet is waiting?
            return True

        return GPIO.wait_for_edge(self.irq_pin, GPIO.FALLING, timeout) == 1
项目:BlogCode    作者:yaptb    | 项目源码 | 文件源码
def event_loop(self):


            self.keyDown=False
        self.hitCount=0 


            keys_per_rev=5
            key_press_delay=0.2
            inter_key_delay=0.001

            self.last_hit_time=0
            self.current_hit_time=0
            self.rev_time=0.5

            GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=250) 


            while True:


                if(self.hitCount >0):

                        if(not self.keyDown):
                            print "On"    
                            self.state[4]=DeskCycle.KEYCODE
                            self.send_key_state()
                            self.keyDown=True

                        self.hitCount=0

                else:
                        if(self.keyDown):

                                if(time.time()-self.last_hit_time > 1):
                                        print "Off"    
                                        self.state[4]=0
                                        self.send_key_state()
                                        self.keyDown=False

                time.sleep(0.001)
项目:BlogCode    作者:yaptb    | 项目源码 | 文件源码
def __init__(self):


            print "setting up GPIO"

            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(DeskCycle.PIN,GPIO.IN,pull_up_down=GPIO.PUD_UP)

            self.hitCount=0

            pin2=38
            GPIO.setup(pin2,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
            GPIO.add_event_detect(pin2, GPIO.FALLING, callback=self.pin_2_event,bouncetime=100)
项目:RPiNWR    作者:ke4roh    | 项目源码 | 文件源码
def reset_radio(self):
        """
        Reset the Si4707 chip
        """
        # Ref https://github.com/AIWIndustries/Pi_4707/blob/master/firmware/NWRSAME_v2.py
        if self.gpio_started:
            gpio.cleanup()
        self.gpio_started = True
        gpio.setmode(gpio.BCM)  # Use board pin numbering

        gpio.setup(17, gpio.OUT)  # Setup the reset pin
        gpio.output(17, gpio.LOW)  # Reset the Si4707.
        sleep(0.4)
        gpio.output(17, gpio.HIGH)

        gpio.setup(23, gpio.IN, pull_up_down=gpio.PUD_UP)
        gpio.add_event_detect(23, gpio.FALLING)

        # Initialize the onboard relays
        for pin in self.relay_gpio_pins:
            gpio.setup(pin, gpio.OUT)  # setup gpio pin for relay
            gpio.output(pin, gpio.LOW)  # boot to disabled state

        # set up the LED
        # https://www.reddit.com/r/raspberry_pi/comments/3641ug/blinking_an_onboard_led_on_the_pi_2_model_b/
        # http://raspberrypi.stackexchange.com/questions/697/how-do-i-control-the-system-leds-using-my-
        # sudo echo none >/sys/class/leds/led0/trigger
        # GPIO 16 LOW is on, HIGH is off
        gpio.setup(16, gpio.OUT)
        gpio.output(16, gpio.HIGH)

        sleep(1.5)
项目:Pacbot    作者:HarvardURC    | 项目源码 | 文件源码
def __init__(self):

        GPIO.setmode(GPIO.BCM)
        #Setup each hall effect pin for interrupts
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        print ("Encoders Ready")

        GPIO.add_event_detect(18, GPIO.FALLING, callback=self.add_right_pulse)
        GPIO.add_event_detect(24, GPIO.FALLING, callback=self.add_left_pulse)

        while 1:
            pass

    # Callback function for Hall Sensor interrupts
项目:RaspberryPi-MPD-CharDisplay    作者:bill6300gp    | 项目源码 | 文件源码
def eventBegin(self, callback, object=0, edge='BOTH'):
    # eventBegin(callback)
    # eventBegin(callback, object, edge)
    # ** callback: call function when Interrupt
    # ** object: set Interrupt pin: 1=Button, 2=Encoder  >> default: 0(all)
    # ** edge: set edge detection: RISING, FALLING, BOTH >> default: BOTH
    self.Callback=callback

    if object==0 and ((self.__SWtype==1 and self.__eventStatus&0x03!=0x00) or (self.__SWtype==2 and self.__eventStatus&0x0F!=0x00)):
      self.eventEnd(0)
    elif object==1 and self.__eventStatus&0x03!=0x00:
      self.eventEnd(1)
    elif object==2 and (self.__SWtype==2 and self.__eventStatus&0x0C!=0x00):
      self.eventEnd(2)

    if object==0 or object==1:
      if edge.upper().find('RISING')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.RISING, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x01
      elif edge.upper().find('FALLING')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.FALLING, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x02
      elif edge.upper().find('BOTH')>=0:
        GPIO.add_event_detect(self.__PinSW, GPIO.BOTH, callback=self.eventButton, bouncetime=40)
        self.__eventStatus|=0x03
    if (object==0 or object==2) and self.__SWtype==2:
      if edge.upper().find('RISING')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.RISING, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x04
      elif edge.upper().find('FALLING')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.FALLING, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x08
      elif edge.upper().find('BOTH')>=0:
        GPIO.add_event_detect(self.__PinA , GPIO.BOTH, callback=self.eventEncoder, bouncetime=20)
        self.__eventStatus|=0x0C
项目:JustBoom    作者:PiSupply    | 项目源码 | 文件源码
def start(self):
        GPIO.add_event_detect(self.clockPin,
                              GPIO.FALLING,
                              callback=self._clockCallback,
                              bouncetime=50)
        GPIO.add_event_detect(self.buttonPin,
                              GPIO.FALLING,
                              callback=self._switchCallback,
                              bouncetime=300)
项目:foosballtable-hack    作者:eskape    | 项目源码 | 文件源码
def __setup(self, channels):
    self.__mappings = {}
    number = 0
    for channel in channels:
      number += 1
      GPIO.setup(channel, GPIO.IN)
      GPIO.add_event_detect(channel, GPIO.FALLING, callback=self.__teamscores)
      self.__mappings[channel] = number
      logging.info("Listening for events for %s on channel %s" % (self.__mappings[channel], channel))
项目:pideck    作者:pideck    | 项目源码 | 文件源码
def start(self):
        GPIO.add_event_detect(self.clockPin, GPIO.FALLING, callback=self._clockCallback, bouncetime=self.DEBOUNCE)
        GPIO.add_event_detect(self.switchPin, GPIO.FALLING, callback=self.switchCallback, bouncetime=self.DEBOUNCE)
项目:PiCons    作者:bgerp    | 项目源码 | 文件源码
def init_c1(self, reset = True):
        if(reset):
            self.reset_counter1()

        self.__soft_debounce_1 = False
        GPIO.add_event_detect(self.__input_pins[0], GPIO.FALLING, callback=self.__worker_c1)

    ## Initialize counter 1.
    #  @param self The object pointer.
    #  @param reset Reset the counter.
项目:PiCons    作者:bgerp    | 项目源码 | 文件源码
def init_c2(self, reset=True):
        if(reset):
            self.reset_counter2()

        self.__soft_debounce_2 = False
        GPIO.add_event_detect(self.__input_pins[1], GPIO.FALLING, callback=self.__worker_c2)

    ## Retuens counter 1 value.
    #  @param self The object pointer.
    #  @return Counter 1 value.
项目:SunFounder_Super_Kit_V3.0_for_Raspberry_Pi    作者:sunfounder    | 项目源码 | 文件源码
def setup():
    # Set the GPIO modes to BCM Numbering
    GPIO.setmode(GPIO.BCM)
    # Set LedPin's mode to output, 
    # and initial level to high (3.3v)
    GPIO.setup(LedPin, GPIO.OUT, initial=GPIO.HIGH)
    # Set BtnPin's mode to input, 
    # and pull up to high (3.3V)
    GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    # Set up a falling detect on BtnPin, 
    # and callback function to swLed
    GPIO.add_event_detect(BtnPin, GPIO.FALLING, callback=swLed)

# Define a callback function for button callback
项目:Sample-Code    作者:meigrafd    | 项目源码 | 文件源码
def __init__(self):
        ''' initialize the pin for the anemometer sensor '''
        self.SENSOR_PIN = 4
        self.count = 0
        # tell the GPIO module that we want to use the chip's pin numbering scheme
        GPIO.setmode(GPIO.BCM)
        # setup pin as an input with pullup
        GPIO.setup(self.SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # threaded event, to detect voltage falling on anemometer
        # bouncetime is in ms - edges within this time will be ignored
        GPIO.add_event_detect(self.SENSOR_PIN, GPIO.FALLING, bouncetime=30)
        self.starttime = time.time()
        # deal with events by calling a function
        GPIO.add_event_callback(self.SENSOR_PIN, self.inputEventHandler)
项目:kegbot-pi-flowmeter    作者:stevenpinewebair    | 项目源码 | 文件源码
def main():
    #initial build out
    GPIO.add_event_detect(17, GPIO.FALLING, callback=sensorCallback1)
    stillAlive()
    try:
        while True:
            time.sleep(1)
            #logging.info('in sleep loop')
            #push this off to definition
            if(fm.clicks > 0):
                pourDrinkEvent(fm.clicks)
    except KeyboardInterrupt:
        GPIO.cleanup()