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


Python Pin.off方法代码示例

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


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

示例1: Ultrasonic

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import off [as 别名]
class Ultrasonic(object):
    def __init__(self, trigger_pin, echo_pin, timeout_us=30000):
        # WARNING: Don't use PA4-X5 or PA5-X6 as echo pin without a 1k resistor

        # Default timeout is a bit more than the HC-SR04 max distance (400 cm):
        # 400 cm * 29 us/cm (speed of sound ~340 m/s) * 2 (round-trip)

        self.timeout = timeout_us

        # Init trigger pin (out)
        self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None)
        self.trigger.off()

        # Init echo pin (in)
        self.echo = Pin(echo_pin, mode=Pin.IN, pull=None)

    def distance_in_inches(self):
        return (self.distance_in_cm() * 0.3937)

    def distance_in_cm(self):
        # Send a 10us pulse
        self.trigger.on()
        sleep_us(10)
        self.trigger.off()

        # Wait for the pulse and calc its duration
        time_pulse = time_pulse_us(self.echo, 1, self.timeout)

        if time_pulse < 0:
            raise MeasurementTimeout(self.timeout)

        # Divide the duration of the pulse by 2 (round-trip) and then divide it
        # by 29 us/cm (speed of sound = ~340 m/s)
        return (time_pulse / 2) / 29
开发者ID:skgsergio,项目名称:MicropythonLibs,代码行数:36,代码来源:ultrasonic.py

示例2: Pin

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import off [as 别名]
# 残10分から表示し、時間ぎれで点滅+ブザー鳴らす。
# 2017-03-21 by penkich
# 
from machine import Pin,I2C,Timer
from neopixel import NeoPixel
import time

npix = 4 # 1セグを構成するNeoPixelの個数
t = 50 # 時間設定(分) 

pin = Pin(4,Pin.OUT) # NeoPixelの信号線を接続
np = NeoPixel(pin, 7 * npix)
buz = Pin(5,Pin.OUT) # 圧電ブザーを接続
buz.on() # 起動時に少し鳴らす
time.sleep(1)
buz.off()

def seg7(n,rgb):
    data = [0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe4,0xfe,0xe6,0xee]
    x = data[n] >> 1
    out = []
    for i in range(7): 
        if x % 2:
            out.append(rgb)
        else:
            out.append(blank)
        x = x >> 1
    out.reverse()
    tmp = []
    for x in out:
        tmp = tmp + x # 1次配列に変換
开发者ID:penkich,项目名称:esp8266-micropython,代码行数:33,代码来源:big7segtimer.py


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