本文整理汇总了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()
示例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))
示例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()
示例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")
示例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))