當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。