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


Python Pin.PULL_UP属性代码示例

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


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

示例1: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [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 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:22,代码来源:trigger.py

示例2: get_spi

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def get_spi(self): 
        spi = None
        id = 1
        
        if config_lora.IS_ESP8266:
            spi = SPI(id, baudrate = 10000000, polarity = 0, phase = 0)
            spi.init()
            
        if config_lora.IS_ESP32:
            try:
                if config_lora.SOFT_SPI: id = -1              
                spi = SPI(id, baudrate = 10000000, polarity = 0, phase = 0, bits = 8, firstbit = SPI.MSB,
                          sck = Pin(self.PIN_ID_SCK, Pin.OUT, Pin.PULL_DOWN),
                          mosi = Pin(self.PIN_ID_MOSI, Pin.OUT, Pin.PULL_UP),
                          miso = Pin(self.PIN_ID_MISO, Pin.IN, Pin.PULL_UP))
                spi.init()
                    
            except Exception as e:
                print(e)
                if spi: 
                    spi.deinit()
                    spi = None
                reset()  # in case SPI is already in use, need to reset. 
        
        return spi 
开发者ID:Wei1234c,项目名称:SX127x_driver_for_MicroPython_on_ESP8266,代码行数:27,代码来源:controller_esp.py

示例3: test_sw

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_sw():
    s = '''
close pulses green
open pulses red
'''
    print('Test of switch scheduling coroutines.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register coros to launch on contact close and open
    sw.close_func(pulse, (green, 1000))
    sw.open_func(pulse, (red, 1000))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer())

# Test for the switch class with a callback 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:21,代码来源:switches.py

示例4: test_swcb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_swcb():
    s = '''
close toggles red
open toggles green
'''
    print('Test of switch executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register a coro to launch on contact close
    sw.close_func(toggle, (red,))
    sw.open_func(toggle, (green,))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer())

# Test for the Pushbutton class (coroutines)
# Pass True to test suppress 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:switches.py

示例5: test_btncb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_btncb():
    s = '''
press toggles red
release toggles green
double click toggles yellow
long press toggles blue
'''
    print('Test of pushbutton executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    yellow = LED(3)
    blue = LED(4)
    pb = Pushbutton(pin)
    pb.press_func(toggle, (red,))
    pb.release_func(toggle, (green,))
    pb.double_func(toggle, (yellow,))
    pb.long_func(toggle, (blue,))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer()) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:24,代码来源:switches.py

示例6: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [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() 
开发者ID:ayoy,项目名称:upython-aq-monitor,代码行数:19,代码来源:sht1x.py

示例7: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def __init__(self, reset, dc, busy, cs, clk, mosi):
        self.reset_pin = reset
        self.reset_pin.mode(Pin.OUT)

        self.dc_pin = dc
        self.dc_pin.mode(Pin.OUT)

        self.busy_pin = busy
        self.busy_pin.mode(Pin.IN)

        self.cs_pin = cs
        self.cs_pin.mode(Pin.OUT)
        self.cs_pin.pull(Pin.PULL_UP)

        self.spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=0, phase=0, pins=(clk, mosi, None))

        self.width = EPD_WIDTH
        self.height = EPD_HEIGHT
        self.rotate = ROTATE_0 
开发者ID:ayoy,项目名称:micropython-waveshare-epd,代码行数:21,代码来源:epd1in54b.py

示例8: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def __init__(self, name, pin, *args,
                 report_high="on", report_low="off",
                 pullup=True, threshold=0,
                 on_change=None, report_change=True, filter=None):
        if len(args) > 0:
            report_high = args[0]
            if len(args) > 1:
                report_low = args[1]
        Device.__init__(self, name, pin,
                        value_map={True: report_high,
                                   False: report_low},
                        on_change=on_change,
                        report_change=report_change, filter=filter)
        if pullup:
            pin.init(Pin.IN, Pin.PULL_UP)
        else:
            pin.init(Pin.IN)
            try:
                Pin.init(Pin.OPEN_DRAIN)
            except:
                pass
        self.threshold = threshold + 1
        self.debouncer = self.port() * self.threshold 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:25,代码来源:contact.py

示例9: pull

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def pull(self, pul):
        if self.direction is Direction.INPUT:
            self.__pull = pul
            if pul is Pull.UP:
                self._pin.init(mode=Pin.IN, pull=Pin.PULL_UP)
            elif pul is Pull.DOWN:
                if hasattr(Pin, "PULL_DOWN"):
                    self._pin.init(mode=Pin.IN, pull=Pin.PULL_DOWN)
                else:
                    raise NotImplementedError(
                        "{} unsupported on {}".format(Pull.DOWN, board_id)
                    )
            elif pul is None:
                self._pin.init(mode=Pin.IN, pull=None)
            else:
                raise AttributeError("Not a Pull")
        else:
            raise AttributeError("Not an input") 
开发者ID:adafruit,项目名称:Adafruit_Blinka,代码行数:20,代码来源:digitalio.py

示例10: test_sw

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_sw():
    s = '''
close pulses green
open pulses red
'''
    print('Test of switch scheduling coroutines.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register coros to launch on contact close and open
    sw.close_func(pulse, (green, 1000))
    sw.open_func(pulse, (red, 1000))
    run()

# Test for the switch class with a callback 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:20,代码来源:switches.py

示例11: test_swcb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_swcb():
    s = '''
close toggles red
open toggles green
'''
    print('Test of switch executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register a coro to launch on contact close
    sw.close_func(toggle, (red,))
    sw.open_func(toggle, (green,))
    run()

# Test for the Pushbutton class (coroutines)
# Pass True to test suppress 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:21,代码来源:switches.py

示例12: test_btncb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def test_btncb():
    s = '''
press toggles red
release toggles green
double click toggles yellow
long press toggles blue
'''
    print('Test of pushbutton executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    yellow = LED(3)
    blue = LED(4)
    pb = Pushbutton(pin)
    pb.press_func(toggle, (red,))
    pb.release_func(toggle, (green,))
    pb.double_func(toggle, (yellow,))
    pb.long_func(toggle, (blue,))
    run() 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:23,代码来源:switches.py

示例13: init_lora

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def init_lora():
    """Initialize LoRaWAN connection"""

    if not Pin(LORA_ENABLE_PIN, mode=Pin.IN, pull=Pin.PULL_UP)():
        lora = None
    else:
        if LORA_MODE.lower() == 'otaa':
            lora = join_otaa()
        elif LORA_MODE.lower() == 'abp':
            lora = join_abp()
        else:
            lora = None

    if lora is None:
        log('LoRa disabled!')
        return (None, None)

    # Setup socket
    sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    sock.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)      # Set data rate
    sock.setblocking(False)

    log('Done!')
    return (lora, sock) 
开发者ID:ttn-be,项目名称:ttnmapper,代码行数:26,代码来源:ttnmapper.py

示例14: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def __init__(self, name="Onboard LED", pin=2):
        super().__init__(id="led", name=name, type="LED")
        self.pin = pin
        self.led = Pin(pin, Pin.OUT, value=0)
        self.btn = Pushbutton(Pin(0, Pin.IN, Pin.PULL_UP))
        self.btn.press_func(self.toggle_led)

        self.power_property = HomieNodeProperty(
            id="power",
            name="LED Power",
            settable=True,
            datatype=BOOLEAN,
            default=TRUE,
        )

        self.add_property(self.power_property, self.on_power_msg) 
开发者ID:microhomie,项目名称:microhomie,代码行数:18,代码来源:main.py

示例15: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import PULL_UP [as 别名]
def __init__(self):
        super().__init__(
            id="relay", name="Wifi Power Socket", type="OW8266-02Q"
        )
        self.led = Pin(4, Pin.OUT, value=1)
        self.r_on = Pin(12, Pin.OUT)
        self.r_off = Pin(5, Pin.OUT)

        self.power_property = HomieNodeProperty(
            id="power",
            name="Relay",
            settable=True,
            retained=True,
            datatype=BOOLEAN,
            default=FALSE,
            restore=True,
        )
        self.add_property(self.power_property, self.on_power_msg)

        self.button = Pushbutton(Pin(14, Pin.IN, Pin.PULL_UP))
        self.button.release_func(self.toggle, ())
        self.button.long_func(reset, (self.led,)) 
开发者ID:microhomie,项目名称:microhomie,代码行数:24,代码来源:main.py


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