当前位置: 首页>>代码示例>>Python>>正文


Python GPIO.FALLING属性代码示例

本文整理汇总了Python中RPi.GPIO.FALLING属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.FALLING属性的具体用法?Python GPIO.FALLING怎么用?Python GPIO.FALLING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在RPi.GPIO的用法示例。


在下文中一共展示了GPIO.FALLING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def __init__(self,
                 channel,
                 polarity=GPIO.FALLING,
                 pull_up_down=GPIO.PUD_UP,
                 debounce_time=0.08):
        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.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)

        self.callback = None 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:21,代码来源:_button.py

示例2: event_loop

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
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) 
开发者ID:yaptb,项目名称:BlogCode,代码行数:22,代码来源:deskcycle_test.py

示例3: start

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
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() 
开发者ID:alexa-pi,项目名称:AlexaPiDEPRECATED,代码行数:23,代码来源:main.py

示例4: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def setup():
    global _is_setup

    if _is_setup:
        return True

    atexit.register(_exit)

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup([DAT, CLK], GPIO.OUT)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    for button in BUTTONS:
        GPIO.add_event_detect(button, GPIO.FALLING, callback=_handle_button, bouncetime=200)

    _is_setup = True 
开发者ID:pimoroni,项目名称:phat-beat,代码行数:19,代码来源:__init__.py

示例5: main

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def main():
    global pulses

    ## We're using BCM Mode
    GPIO.setmode(GPIO.BCM)

    ## Setup coin interrupt channel
    GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    # GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
    GPIO.add_event_detect(6, GPIO.FALLING, callback=coinEventHandler)

    while True:
        time.sleep(0.5)
        if (time.time() - lastImpulse > 0.5) and (pulses > 0):
            if pulses == 1:
                print("Coin 1")
            pulses = 0

    GPIO.cleanup()


# handle the coin event 
开发者ID:21isenough,项目名称:LightningATM,代码行数:24,代码来源:acceptor_test.py

示例6: on

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def on(buttons, bounce=BOUNCE):
    """Handle a joystick direction or button push

    Decorator. Use with @joystick.on(joystick.UP)

    :param buttons: List, or single instance of joystick button constant
    :param bounce: Debounce delay in milliseconds: default 300

    """

    buttons = buttons if isinstance(buttons, list) else [buttons]

    def register(handler):
        for button in buttons:
            GPIO.remove_event_detect(button)
            GPIO.add_event_detect(button, GPIO.FALLING, callback=handler, bouncetime=bounce)

    return register 
开发者ID:pimoroni,项目名称:displayotron,代码行数:20,代码来源:joystick.py

示例7: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
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.") 
开发者ID:jedimatt42,项目名称:tipi,代码行数:21,代码来源:TipiWatchDogService.py

示例8: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
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 
开发者ID:sunfounder,项目名称:SunFounder_Super_Kit_V3.0_for_Raspberry_Pi,代码行数:18,代码来源:12_rotaryEncoder.py

示例9: start_filament_detection

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def start_filament_detection(self):
        self.stop_filament_detection()
        try:
            for filament_sensor in list(filter(
                    lambda item: item['input_type'] == 'gpio' and item['action_type'] == 'printer_control' and item[
                        'printer_action'] == 'filament', self.rpi_inputs)):
                edge = GPIO.RISING if filament_sensor['edge'] == 'rise' else GPIO.FALLING
                if GPIO.input(self.to_int(filament_sensor['gpio_pin'])) == (edge == GPIO.RISING):
                    self._printer.pause_print()
                    self._logger.info("Started printing with no filament.")
                else:
                    self.last_filament_end_detected.append(dict(index_id=filament_sensor['index_id'], time=0))
                    self._logger.info("Adding GPIO event detect on pin %s with edge: %s", filament_sensor['gpio_pin'],
                        edge)
                    GPIO.add_event_detect(self.to_int(filament_sensor['gpio_pin']), edge,
                        callback=self.handle_filamment_detection, bouncetime=200)
        except Exception as ex:
            self.log_error(ex) 
开发者ID:vitormhenrique,项目名称:OctoPrint-Enclosure,代码行数:20,代码来源:__init__.py

示例10: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def __init__(self,
                 controller: Controller,
                 button_gpio: int = 26,
                 led_gpio: int = 21) -> None:
        self.button_gpio = button_gpio
        self.controller = controller
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(button_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(led_gpio, GPIO.OUT)
        self.led_gpio = led_gpio

        def call_back(channel: int) -> None:
            def new_thread():
                self.controller.update_and_redraw()
                logger.info('Update of the screen due to button event')

            thread = threading.Thread(target=new_thread)
            thread.start()

        GPIO.add_event_detect(button_gpio,
                              GPIO.FALLING,
                              callback=call_back,
                              bouncetime=500)
        self.led_off() 
开发者ID:zli117,项目名称:EInk-Calendar,代码行数:26,代码来源:button_and_led.py

示例11: init

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def init(self, switch_pin=None, clock_pin=None, data_pin=None, **kwargs):
        _log.info("setup")
        self._switch_pin = switch_pin
        self._clock_pin = clock_pin
        self._data_pin = data_pin
        
        gpio.setmode(gpio.BCM)

        if self._switch_pin:
            _log.info("Setting up button pin")
            gpio.setup(self._switch_pin, gpio.IN, gpio.PUD_UP)
            gpio.add_event_detect(self._switch_pin, gpio.BOTH, callback=self._switch_cb, bouncetime=2)
            
        if self._data_pin:
            _log.info("Setting up data pin")
            gpio.setup(self._data_pin, gpio.IN)

        if self._clock_pin:
            gpio.setup(self._clock_pin, gpio.IN, gpio.PUD_UP)
            gpio.add_event_detect(self._clock_pin, gpio.FALLING, callback=self._knob_cb, bouncetime=2)
            
        self._values = []
        
        _log.info("Systems are go") 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:26,代码来源:GPIOKY040.py

示例12: _trigger

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def _trigger(self):
        try :
            self._detection = True
            self._t0 = time.time()
            gpio.output(self._trigger_pin, gpio.HIGH)
            time.sleep(0.00005)
            gpio.output(self._trigger_pin, gpio.LOW)
            pin = gpio.wait_for_edge(self._echo_pin, gpio.FALLING, timeout=1000)
            self._elapsed = time.time() - self._t0

            if pin is None:
                _log.debug("echo timeout exceeded") #

            self._detection = None
            async.call_from_thread(self.scheduler_wakeup)


        except Exception as e:
            _log.warning("Failed sonar triggering: {}".format(e)) 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:21,代码来源:GPIOSR04.py

示例13: pushbutton

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def pushbutton(self):
        if GPIOcontrol:
            while mutestopbutton:
                time.sleep(.1)
                if GPIO.event_detected(stoppushbutton):
                    GPIO.remove_event_detect(stoppushbutton)
                    now = time.time()
                    count = 1
                    GPIO.add_event_detect(stoppushbutton,GPIO.RISING)
                    while time.time() < now + 1:
                         if GPIO.event_detected(stoppushbutton):
                             count +=1
                             time.sleep(.25)
                    if count == 2:
                        self.buttonsinglepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
                    elif count == 3:
                        self.buttondoublepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
                    elif count == 4:
                        self.buttontriplepress()
                        GPIO.remove_event_detect(stoppushbutton)
                        GPIO.add_event_detect(stoppushbutton,GPIO.FALLING) 
开发者ID:shivasiddharth,项目名称:GassistPi,代码行数:27,代码来源:main.py

示例14: initialize

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def initialize(self):
        try:
            GPIO.setmode(GPIO.BCM)
            GPIO.setwarnings(False)
            GPIO.setup(LED, GPIO.OUT)
            GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(BUTTON, GPIO.FALLING, bouncetime = 500)
        except GPIO.error:
            self.log.warning("Can't initialize GPIO - skill will not load")
            self.speak_dialog("error.initialise")
        finally:
            self.schedule_repeating_event(self.handle_button,
                                          None, 0.1, 'GoogleAIY')
            self.add_event('recognizer_loop:record_begin',
                           self.handle_listener_started)
            self.add_event('recognizer_loop:record_end',
                           self.handle_listener_ended) 
开发者ID:andlo,项目名称:picroft-google-aiy-voicekit-skill,代码行数:19,代码来源:__init__.py

示例15: haltSystem

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import FALLING [as 别名]
def haltSystem():
    print 'Halt...'
    os.system("sudo halt")
    
# GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000) 
开发者ID:pierre-muth,项目名称:polapi-zero,代码行数:7,代码来源:polapizero_09.py


注:本文中的RPi.GPIO.FALLING属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。