本文整理匯總了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