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


Python GPIO.wait_for_edge方法代码示例

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


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

示例1: start

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import wait_for_edge [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

示例2: _trigger

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import wait_for_edge [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

示例3: firstFunction

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import wait_for_edge [as 别名]
def firstFunction():
    global counter
    global ts
    global counting
    count = 1
    counter = 0
    ts = time.time()
    while True:
        if count == 1:
            GPIO.wait_for_edge(6, GPIO.FALLING)
            counting = 1
            counter += 1
            print(f"Pulse comming ! {counter}")
            ts = time.time() 
开发者ID:21isenough,项目名称:LightningATM,代码行数:16,代码来源:coinacceptor.py

示例4: ircommands

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import wait_for_edge [as 别名]
def ircommands(self):
        if irreceiver!=None:
            try:
                print("IR Sensor Started")
                while True:
                    time.sleep(.1)
                    #print("Listening for IR Signal on GPIO "+irreceiver)
                    GPIO.wait_for_edge(irreceiver, GPIO.FALLING)
                    code = on_ir_receive(irreceiver)
                    if code:
                        if self.can_start_conversation == True:
                            for codenum, usercode in enumerate(configuration['IR']['Codes']):
                                if usercode==code:
                                    if 'custom' in (configuration['IR']['Commands'][codenum]).lower():
                                        self.custom_command((configuration['IR']['Commands'][codenum]).lower())
                                    elif 'start conversation' in (configuration['IR']['Commands'][codenum]).lower():
                                        self.assistant.start_conversation()
                                    elif 'mute' in (configuration['IR']['Commands'][codenum]).lower():
                                        self.buttonsinglepress()
                                    else:
                                        self.assistant.send_text_query(configuration['IR']['Commands'][codenum])
                                    break
            except KeyboardInterrupt:
                pass
            except RuntimeError:
                pass
            print("Stopping IR Sensor") 
开发者ID:shivasiddharth,项目名称:GassistPi,代码行数:29,代码来源:main.py

示例5: buttonCallback

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import wait_for_edge [as 别名]
def buttonCallback(self, channel):
        """Callback function for user input (pressed buttons)"""

        # record button state transitions
        if channel == RECORD_BUTTON:
            # if the current state is IDLE change it to RECORD
            if self.state == IDLE:
                # set RECORD state
                self.setState(RECORD)

                # empty payloads list
                self.payloads = []

            # if the current state is RECORD change it to IDLE
            elif self.state == RECORD:
                # set IDLE state
                self.setState(IDLE)

        # play button state transitions
        elif channel == REPLAY_BUTTON:
            # if the current state is IDLE change it to REPLAY
            if self.state == IDLE:
                # set REPLAY state
                self.setState(REPLAY)

        # scan button state transitions
        elif channel == SCAN_BUTTON:
            # wait a short a time to see whether the record button is also
            # press in order to perform a graceful shutdown

            # remove event detection for record button
            GPIO.remove_event_detect(RECORD_BUTTON)
            chan = GPIO.wait_for_edge(RECORD_BUTTON, GPIO.RISING, timeout=1000)
            if chan != None:
                # set SHUTDOWN state
                self.setState(SHUTDOWN)

            # set callback function for record button
            GPIO.remove_event_detect(RECORD_BUTTON)
            GPIO.add_event_detect(RECORD_BUTTON, GPIO.RISING, callback = self.buttonCallback, bouncetime = 250)

            # if the current state is IDLE change it to SCAN
            if self.state == IDLE:
                # set SCAN state
                self.setState(SCAN)

        # attack button state transitions
        elif channel == ATTACK_BUTTON:
            # if the current state is IDLE change it to ATTACK
            if self.state == IDLE:
                # set ATTACK state
                self.setState(ATTACK)

        # debug output
        debug("State: {0}".format(self.state)) 
开发者ID:SySS-Research,项目名称:radio-hackbox,代码行数:57,代码来源:radiohackbox.py


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