當前位置: 首頁>>代碼示例>>Python>>正文


Python Pin.OUT屬性代碼示例

本文整理匯總了Python中machine.Pin.OUT屬性的典型用法代碼示例。如果您正苦於以下問題:Python Pin.OUT屬性的具體用法?Python Pin.OUT怎麽用?Python Pin.OUT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在machine.Pin的用法示例。


在下文中一共展示了Pin.OUT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: playnotes

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def playnotes(self, title, length=150, duty=64):
        # Init
        p = Pin(27, Pin.OUT)
        self.pwm = PWM(p)
        self.pwm.duty(0)

        if title not in self.notes:
          print('unknown title: {}'.format(title))
          return

        melody = self.notes[title]
        print('Play', title)
        for i in melody:
            if i == 0:
                self.pwm.duty(0)
            else:
                self.pwm.freq(i)
                self.pwm.duty(duty)
            time.sleep_ms(length)

        # deinit
        self.pwm.deinit() 
開發者ID:IBM-Developer-Korea,項目名稱:developer-badge-2018-apps,代碼行數:24,代碼來源:buzzer.py

示例2: get_spi

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [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: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def __init__(self):
        self.notes = {
            'cdef': [
                self.C6, self.D6, self.E6, self.F6, self.G6, self.A6, self.B6, self.C7, self.D7, self.E7, self.F7, self.G7, self.A7, self.B7, self.C8, 0
            ],
            'mario': [
                self.E7, self.E7,  0, self.E7,  0, self.C7, self.E7,  0, self.G7,  0,  0,  0, self.G6,  0,  0,  0,
                self.C7,  0,  0, self.G6,  0,  0, self.E6,  0,  0, self.A6,  0, self.B6,  0, self.AS6, self.A6, 0,
                self.G6, self.E7,  0, self.G7, self.A7,  0, self.F7, self.G7,  0, self.E7,  0, self.C7, self.D7, self.B6,  0,  0,
                self.C7,  0,  0, self.G6,  0,  0, self.E6,  0,  0, self.A6,  0, self.B6,  0, self.AS6, self.A6, 0,
                self.G6, self.E7,  0, self.G7, self.A7,  0, self.F7, self.G7,  0, self.E7,  0, self.C7, self.D7, self.B6,  0,  0
            ],
            'starwars': [
                self.A4,  0,  0,  0, self.A4,  0,  0,  0, self.A4,  0,  0,  0, self.F4,  0,  0, self.C5,
                self.A4,  0,  0,  0, self.F4,  0,  0, self.C5, self.A4,  0,  0,  0,  0,  0,  0,  0,
                self.E5,  0,  0,  0, self.E5,  0,  0,  0, self.E5,  0,  0,  0, self.F5,  0,  0, self.C5,
                self.GS4, 0,  0,  0, self.F4,  0,  0, self.C5, self.A4,  0,  0,  0,  0,  0,  0,  0,
            ],
        }

        # Init
        self.pwm = PWM(Pin(27, Pin.OUT))
        self.pwm.duty(0) 
開發者ID:IBM-Developer-Korea,項目名稱:developer-badge-2018-apps,代碼行數:25,代碼來源:buzzer.py

示例4: digital_write

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [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 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:18,代碼來源:esp_8266Full.py

示例5: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def __init__(self, sck, mosi, miso, rst, cs):

		self.sck = Pin(sck, Pin.OUT)
		self.mosi = Pin(mosi, Pin.OUT)
		self.miso = Pin(miso)
		self.rst = Pin(rst, Pin.OUT)
		self.cs = Pin(cs, Pin.OUT)

		self.rst.value(0)
		self.cs.value(1)
		
		board = uname()[0]

		if board == 'WiPy' or board == 'LoPy' or board == 'FiPy':
			self.spi = SPI(0)
			self.spi.init(SPI.MASTER, baudrate=1000000, pins=(self.sck, self.mosi, self.miso))
		elif board == 'esp8266':
			self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso)
			self.spi.init()
		else:
			raise RuntimeError("Unsupported platform")

		self.rst.value(1)
		self.init() 
開發者ID:wendlers,項目名稱:micropython-mfrc522,代碼行數:26,代碼來源:mfrc522.py

示例6: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [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 OUT [as 別名]
def __init__(self, idx, is_debug=False):
        
        gpio_a, gpio_b, self.motor_install_dir = Motor.MOTOR_LIST[idx]
        # A相PWM
        self.pwm_a = PWM(
            Pin(gpio_a, Pin.OUT),
            freq = Motor.MOTOR_PWM_FREQUENCY,
            duty = 0)
        
        # B相PWM
        self.pwm_b = PWM(
            Pin(gpio_b, Pin.OUT),
            freq = Motor.MOTOR_PWM_FREQUENCY,
            duty = 0)
        
        # 電機安裝方向
        if not self.motor_install_dir:
            self.pwm_a, self.pwm_b = self.pwm_b, self.pwm_a
        
        # 電機速度信號 取值範圍: -1023 - 1023 
        self._pwm = 0
        # 設置電機的PWM
        # self.pwm(self._pwm) 
開發者ID:1zlab,項目名稱:1ZLAB_PyEspCar,代碼行數:25,代碼來源:motor.py

示例8: set_dotstar_power

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def set_dotstar_power(state):
    """Set the power for the on-board Dostar to allow no current draw when not needed."""
    # Set the power pin to the inverse of state
    if state:
        Pin(DOTSTAR_PWR, Pin.OUT, None)  # Break the PULL_HOLD on the pin
        Pin(DOTSTAR_PWR).value(False)  # Set the pin to LOW to enable the Transistor
    else:
        Pin(13, Pin.IN, Pin.PULL_HOLD)  # Set PULL_HOLD on the pin to allow the 3V3 pull-up to work

    Pin(
        DOTSTAR_CLK, Pin.OUT if state else Pin.IN
    )  # If power is on, set CLK to be output, otherwise input
    Pin(
        DOTSTAR_DATA, Pin.OUT if state else Pin.IN
    )  # If power is on, set DATA to be output, otherwise input

    # A small delay to let the IO change state
    time.sleep(0.035)


# Dotstar rainbow colour wheel 
開發者ID:tinypico,項目名稱:tinypico-micropython,代碼行數:23,代碼來源:tinypico.py

示例9: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [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

示例10: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def __init__(self, name, pin, *args, high_command='on', low_command='off',
                 ignore_case=True, on_change=None, report_change=False):
        if len(args) > 0:
            high_command = args[0]
            if len(args) > 1:
                low_command = args[1]
        if ignore_case:
            high_command = high_command.lower()
            low_command = low_command.lower()
        self.high_command = high_command
        self.low_command = low_command
        Device.__init__(self, name, pin,
                        setters={"set": self.evaluate}, ignore_case=ignore_case,
                        on_change=on_change, report_change=report_change,
                        value_map={1: self.high_command, 0: self.low_command})
        pin.init(Pin.OUT)
        self.state = pin() 
開發者ID:ulno,項目名稱:ulnoiot-upy,代碼行數:19,代碼來源:output.py

示例11: test

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def test():
    print('Test for IR receiver. Assumes NEC protocol. Turn LED on or off.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
        led = LED(2)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
        led = Pin(2, Pin.OUT)
        led(1)
    elif ESP32:
        p = Pin(23, Pin.IN)
        led = Pin(21, Pin.OUT)  # LED with 220Ω series resistor between 3.3V and pin 21
        led(1)
    ir = NEC_IR(p, cb, True, led)  # Assume extended address mode r/c
    loop = asyncio.get_event_loop()
    loop.run_forever() 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:19,代碼來源:art1.py

示例12: test

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def test():
    print('Test for IR receiver. Assumes NEC protocol. Turn LED on or off.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
        led = LED(2)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
        led = Pin(2, Pin.OUT)
        led(1)
    elif ESP32:
        p = Pin(23, Pin.IN)
        led = Pin(21, Pin.OUT)  # LED with 220Ω series resistor between 3.3V and pin 21
        led(1)
    ir = NEC_IR(p, cb, True, led)  # Assume extended address mode r/c
    loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()  # Still need ctrl-d because of interrupt vector 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:24,代碼來源:art1.py

示例13: heartbeat

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def heartbeat(tms):
    if platform == 'pyboard':  # V1.x or D series
        from pyb import LED
        led = LED(1)
    elif platform == 'esp8266':
        from machine import Pin
        led = Pin(2, Pin.OUT, value=1)
    elif platform == 'linux':
        return  # No LED
    else:
        raise OSError('Unsupported platform.')
    while True:
        if platform == 'pyboard':
            led.toggle()
        elif platform == 'esp8266':
            led(not led())
        await asyncio.sleep_ms(tms) 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:19,代碼來源:heartbeat.py

示例14: test

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [as 別名]
def test():
    freq(160000000)
    dout = Pin(14, Pin.OUT, value = 0)     # Define pins
    ckout = Pin(15, Pin.OUT, value = 0)    # clocks must be initialised to zero.
    din = Pin(13, Pin.IN)
    ckin = Pin(12, Pin.IN)

    channel = SynCom(True, ckin, ckout, din, dout)
    loop = asyncio.get_event_loop()
    loop.create_task(heartbeat())
    loop.create_task(channel.start(passive_task))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        ckout(0) 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:19,代碼來源:sr_passive.py

示例15: __init__

# 需要導入模塊: from machine import Pin [as 別名]
# 或者: from machine.Pin import OUT [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) 
開發者ID:lemariva,項目名稱:uPySensors,代碼行數:18,代碼來源:hcsr04.py


注:本文中的machine.Pin.OUT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。