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


Python machine.time_pulse_us方法代码示例

本文整理汇总了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 
开发者ID:rsc1975,项目名称:micropython-hcsr04,代码行数:20,代码来源:hcsr04.py

示例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 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:19,代码来源:hcsr04.py

示例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 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:12,代码来源:esp_8266Full.py

示例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 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:12,代码来源:esp_8266.py

示例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 
开发者ID:shaoziyang,项目名称:microbit-lib,代码行数:10,代码来源:demo.py

示例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 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:34,代码来源:hcsr04.py

示例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 
开发者ID:lemariva,项目名称:uPySensors,代码行数:28,代码来源:hcsr04.py


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