本文整理汇总了Python中machine.time_pulse_us方法的典型用法代码示例。如果您正苦于以下问题:Python machine.time_pulse_us方法的具体用法?Python machine.time_pulse_us怎么用?Python machine.time_pulse_us使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machine
的用法示例。
在下文中一共展示了machine.time_pulse_us方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _send_pulse_and_wait
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def _send_pulse_and_wait(self):
"""
Send the pulse to trigger and listen on echo pin.
We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received.
"""
self.trigger.value(0) # Stabilize the sensor
time.sleep_us(5)
self.trigger.value(1)
# Send a 10us pulse.
time.sleep_us(10)
self.trigger.value(0)
try:
pulse_time = machine.time_pulse_us(self.echo, 1, self.echo_timeout_us)
return pulse_time
except OSError as ex:
if ex.args[0] == 110: # 110 = ETIMEDOUT
raise OSError('Out of range')
raise ex
示例2: _pulse
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def _pulse(self) -> int:
"""
Send a pulse and wait for the echo pin using machine.time_pulse_us() to measure us.
:return: int
"""
tr = self._tr
tr.value(0)
time.sleep_us(5)
tr.value(1)
time.sleep_us(10)
tr.value(0)
try:
return machine.time_pulse_us(self._ec, 1, self._to)
except OSError as e:
if e.args[0] == 100: # TIMEOUT
raise OSError("Object too far")
raise e
示例3: distance_in_cm
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def distance_in_cm(self):
self.trigger.value(1)
sleep_us(10)
self.trigger.value(0)
try:
time = time_pulse_us(self.echo, 1, 29000)
except OSError:
return None
dist_in_cm = (time / 2.0) / 29
return dist_in_cm
示例4: distance_in_cm
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def distance_in_cm(self):
self.trigger.value(1)
sleep_us(10)
self.trigger.value(0)
try:
time=time_pulse_us(self.echo,1,29000)
except OSError:
return None
dist_in_cm=(time/2.0)/29
return dist_in_cm
示例5: distance
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def distance(tp, ep):
ep.read_digital()
tp.write_digital(1)
sleep_us(10)
tp.write_digital(0)
ts = time_pulse_us(ep, 1, 5000)
if ts > 0: return ts * 17 // 100
return ts
示例6: _send_pulse_and_wait
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def _send_pulse_and_wait(self):
# Send the pulse to trigger and listen on echo pin.
# We use the method `machine.time_pulse_us()` to
# get the microseconds until the echo is received.
self.trigger_pin.value(0) # Stabilize the sensor
sleep_us(5)
self.trigger_pin.on()
# Send a 10us pulse.
sleep_us(10)
self.trigger_pin.off()
# try:
# pulse_time = machine.time_pulse_us(self.echo_pin, 1, self.echo_timeout_us)
# return pulse_time
# except OSError as ex:
# if ex.args[0] == 110: # 110 = ETIMEDOUT
# return -1 # out of range
# raise ex
start = ticks_us()
while not self.echo_pin():
t = ticks_us()
if ticks_diff(t, start) > self.echo_timeout_us:
print("HCR04: timeout")
return -1
start = ticks_us()
while self.echo_pin():
t = ticks_us()
if ticks_diff(t, start) > self.echo_timeout_us:
print("HCR04: timeout")
return -1
delta = ticks_diff(ticks_us(), start)
return delta
示例7: _send_pulse_and_wait
# 需要导入模块: import machine [as 别名]
# 或者: from machine import time_pulse_us [as 别名]
def _send_pulse_and_wait(self):
"""
Send the pulse to trigger and listen on echo pin.
We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received.
"""
self.trigger.value(0) # Stabilize the sensor
time.sleep_us(5)
self.trigger.value(1)
# Send a 10us pulse.
time.sleep_us(10)
self.trigger.value(0)
try:
if (uname().sysname == 'WiPy'):
pulse_list = pulses_get(self.echo, self.echo_timeout_us)
if(len(pulse_list) == 0):
pulse_time = -1
else:
pulse_time = pulse_list[0][1]
else:
pulse_time = time_pulse_us(self.echo, 1, self.echo_timeout_us)
return pulse_time
except OSError as ex:
if ex.args[0] == 110: # 110 = ETIMEDOUT
raise OSError('Out of range')
raise ex