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


Python Pin.IN属性代码示例

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


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

示例1: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [as 别名]
def __init__(self, pin_clk, pin_dt, pin_mode=None, clicks=1, init_val=0,
                 min_val=0, max_val=100, accel=0, reverse=False):
        self.pin_clk = (pin_clk if isinstance(pin_clk, Pin) else
                        Pin(pin_clk, Pin.IN, pin_mode))
        self.pin_dt = (pin_dt if isinstance(pin_dt, Pin) else
                       Pin(pin_dt, Pin.IN, pin_mode))

        self.min_val = min_val * clicks
        self.max_val = max_val * clicks
        self.accel = int((max_val - min_val) / 100 * accel)
        self.max_accel = int((max_val - min_val) / 2)
        self.clicks = clicks
        self.reverse = 1 if reverse else -1

        # The following variables are assigned to in the interrupt callback,
        # so we have to allocate them here.
        self._value = init_val
        self._readings = 0
        self._state = 0
        self.cur_accel = 0

        self.set_callbacks(self._callback) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:24,代码来源:encoder.py

示例3: get_spi

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例4: test_sw

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例5: test_swcb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例6: test_btncb

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例7: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [as 别名]
def __init__(self, gpio_id, is_debug=False):
        self.BV_SAMPLE_PERIOD = 100 # 采样周期(次数)为2000次
        self.OVER_DISCHARGE_VOLTAGE = 6.4 # 过放电压参考值
        self.pin = Pin(gpio_id, Pin.IN) # 电压采样引脚
        self.adc = ADC(self.pin) # 创建引脚对应的ADC对象
        self.init_adc() # 初始化ADC
        
        self.bv_sample_cnt = 0 # 统计次数
        self.bv_sample_sum = 0 # 采样电压总和
        self.battery_voltage = 0 # 电池电压 
        # 初始化电池电压
        self.init_battery_voltage()
        # 创建一个定时器
        # self.timer = Timer(timer_id) 
        # 每隔1ms执行一次
        # self.timer.init(period=1, mode=Timer.PERIODIC, callback=self.callback)
        # 电池是否过放
        self.is_over_discharge = False # 电池是否过放
        # 是否开启调试模式
        self.is_debug = is_debug 
开发者ID:1zlab,项目名称:1ZLAB_PyEspCar,代码行数:22,代码来源:battery_voltage.py

示例8: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [as 别名]
def __init__(self,button_idx, callback=None):
        # 按键字典
        # 数据结构: (GPIO编号,按键抬起的电平, 按键按下的电平)
        button_list = [(39, False, True)]

        if button_idx < 0 or button_idx >= len(button_list):
            print("ERROR: Wrong Button Index")
            print("Valid Button Index: {} - {}".format(0, len(button_list)-1))
            return None

        gpio_id, self.BUTTON_RELEASE, self.BUTTON_PRESS, = button_list[button_idx]
        # 按键
        self.pin = Pin(gpio_id, Pin.IN)
        # 回调函数
        self.callback = callback
        # 设置外部中断
        if self.BUTTON_PRESS == True:
            self.pin.irq(trigger=Pin.IRQ_RISING, handler=self.irq_handler)
        else:
            self.pin.irq(trigger=Pin.IRQ_FALLING, handler=self.irq_handler)
        
        # 标志位 当前是否可以相应按键中断
        self.flag = True 
开发者ID:1zlab,项目名称:1ZLAB_PyEspCar,代码行数:25,代码来源:button.py

示例9: get_battery_charging

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [as 别名]
def get_battery_charging():
    """
    Returns the current battery charging state.
    This can trigger false positives as the charge IC can't tell the difference between a full battery or no battery connected.
    """
    measuredVal = 0  # start our reading at 0
    io = Pin(BAT_CHARGE, Pin.IN)  # Assign the pin to read

    for y in range(
        0, 10
    ):  # loop through 10 times adding the read values together to ensure no false positives
        measuredVal += io.value()

    return measuredVal == 0  # return True if the value is 0


# Power to the on-board Dotstar is controlled by a PNP transistor, so low is ON and high is OFF
# We also need to set the Dotstar clock and data pins to be inputs to prevent power leakage when power is off
# This might be improved at a future date
# The reason we have power control for the Dotstar is that it has a quiescent current of around 1mA, so we
# need to be able to cut power to it to minimise power consumption during deep sleep or with general battery powered use
# to minimise unneeded battery drain 
开发者ID:tinypico,项目名称:tinypico-micropython,代码行数:24,代码来源:tinypico.py

示例10: set_dotstar_power

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例11: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例12: __init__

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例13: pull

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例14: test

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [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

示例15: test

# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import IN [as 别名]
def test():
    print('Test for IR receiver. Assumes NEC protocol.')
    print('ctrl-c to stop.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
    elif ESP32:
        p = Pin(23, Pin.IN)
    ir = NEC_IR(p, cb, True)  # Assume r/c uses extended addressing
    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,代码行数:20,代码来源:art.py


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