本文整理汇总了Python中machine.Pin.OPEN_DRAIN属性的典型用法代码示例。如果您正苦于以下问题:Python Pin.OPEN_DRAIN属性的具体用法?Python Pin.OPEN_DRAIN怎么用?Python Pin.OPEN_DRAIN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类machine.Pin
的用法示例。
在下文中一共展示了Pin.OPEN_DRAIN属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def __init__(self, name, pin,
rising=False, falling=False,
pullup=True, on_change=None, report_change=True):
if pullup:
pin.init(Pin.IN, Pin.PULL_UP)
else:
pin.init(Pin.IN, Pin.OPEN_DRAIN)
if rising and falling:
trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
elif not rising and falling:
trigger = Pin.IRQ_FALLING
else: # also if both all false
trigger = Pin.IRQ_RISING
pin.irq(trigger=trigger, handler=self._cb)
self.counter = 0
self.report_counter = 0
self.triggered = False
Device.__init__(self, name, pin, on_change=on_change,
report_change=report_change)
self.getters[""] = self.value
示例2: digital_write
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def digital_write(self, payload):
"""
Write to a digital gpio pin
:param payload:
:return:
"""
pin = payload['pin']
mode = Pin.OUT
if 'drain' in payload:
if not payload['drain']:
mode = Pin.OPEN_DRAIN
pin_object = Pin(pin, mode)
pwm = PWM(pin_object)
pwm.deinit()
Pin(pin, mode, value=payload['value'])
self.input_pin_objects[pin] = None
示例3: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def __init__(self, gnd, sck, data, vcc):
self.gnd = gnd
self.sck = sck
self.data = data
self.vcc = vcc
self.gnd.mode(Pin.OUT)
self.vcc.mode(Pin.OUT)
self.sck.mode(Pin.OUT)
self.data.mode(Pin.OPEN_DRAIN)
self.gnd.pull(Pin.PULL_DOWN)
self.vcc.pull(Pin.PULL_UP)
self.sck.pull(Pin.PULL_DOWN)
self.data.pull(None)
self.sleep()
示例4: test
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def test():
dout = Pin(Pin.board.Y5, Pin.OUT_PP, value = 0) # Define pins
ckout = Pin(Pin.board.Y6, Pin.OUT_PP, value = 0) # Don't assert clock until data is set
din = Pin(Pin.board.Y7, Pin.IN)
ckin = Pin(Pin.board.Y8, Pin.IN)
reset = Pin(Pin.board.Y4, Pin.OPEN_DRAIN)
sig_reset = Signal(reset, invert = True)
channel = SynCom(False, ckin, ckout, din, dout, sig_reset, 10000)
loop = asyncio.get_event_loop()
loop.create_task(heartbeat())
loop.create_task(channel.start(initiator_task))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
ckout.value(0)
示例5: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def __init__(self, trigger_pin, echo_pin, echo_timeout_us=500*2*30):
"""
trigger_pin: Output pin to send pulses
echo_pin: Readonly pin to measure the distance. The pin should be protected with 1k resistor
echo_timeout_us: Timeout in microseconds to listen to echo pin.
By default is based in sensor limit range (4m)
"""
self.echo_timeout_us = echo_timeout_us
# Init trigger pin (out)
self.trigger = Pin(trigger_pin, mode=Pin.OUT)
self.trigger.value(0)
# Init echo pin (in)
if (uname().sysname == 'WiPy'):
self.echo = Pin(echo_pin, mode=Pin.OPEN_DRAIN)
else:
self.echo = Pin(echo_pin, mode=Pin.IN)
示例6: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def __init__(self, scl, sda):
"""Initiate the HUT21D
Args:
scl (int): Pin id where the sdl pin is connected to
sda (int): Pin id where the sda pin is connected to
"""
self.i2c = I2C(scl=Pin(scl, Pin.OPEN_DRAIN, Pin.PULL_UP), sda=Pin(sda, Pin.OPEN_DRAIN, Pin.PULL_UP), freq=100000)
示例7: set_mode_digital_output
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def set_mode_digital_output(self, payload):
"""
Set pin as a digtal output
:param payload:
:return:
"""
pin = payload['pin']
mode = Pin.OUT
if 'drain' in payload:
if not payload['drain']:
mode = Pin.OPEN_DRAIN
Pin(pin, mode, value=payload['value'])
示例8: digital_write
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def digital_write(self,payload):
pin=payload['pin']
mode=Pin.OUT
if 'drain' in payload:
if not payload['drain']:
mode=Pin.OPEN_DRAIN
pin_object=Pin(pin,mode)
pwm=PWM(pin_object)
pwm.deinit()
Pin(pin,mode,value=payload['value'])
self.input_pin_objects[pin]=None
示例9: set_mode_digital_output
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def set_mode_digital_output(self,payload):
pin=payload['pin']
mode=Pin.OUT
if 'drain' in payload:
if not payload['drain']:
mode=Pin.OPEN_DRAIN
Pin(pin,mode,value=payload['value'])
示例10: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def __init__(self, name, trigger_pin, echo_pin,
echo_timeout_us=30000, precision=10,
on_change=None, report_change=True,
filter=None):
# trigger_pin: Output pin to send pulses
# echo_pin: Readonly pin to measure the distance.
# The pin should be protected with 1k resistor
# echo_timeout_us: Timeout in microseconds to listen to echo pin.
# By default is based in sensor limit range (4m)
self.current_value = 0
self._last_measured = 0
if type(trigger_pin) is not Pin:
trigger_pin = Pin(trigger_pin)
self.trigger_pin = trigger_pin
if type(echo_pin) is not Pin:
echo_pin = Pin(trigger_pin)
self.echo_pin = echo_pin
self.precision = precision
trigger_pin.init(Pin.OUT)
trigger_pin.off()
echo_pin.init(Pin.IN)
echo_pin.init(Pin.OPEN_DRAIN)
self.echo_timeout_us = echo_timeout_us
self.distance = -10000
Device.__init__(self, name, (trigger_pin, echo_pin),
on_change=on_change,
report_change=report_change,
filter=filter)
示例11: drive_mode
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import OPEN_DRAIN [as 别名]
def drive_mode(self, mod):
self.__drive_mode = mod
if mod is DriveMode.OPEN_DRAIN:
self._pin.init(mode=Pin.OPEN_DRAIN)
elif mod is DriveMode.PUSH_PULL:
self._pin.init(mode=Pin.OUT)