本文整理匯總了Python中pyb.Pin方法的典型用法代碼示例。如果您正苦於以下問題:Python pyb.Pin方法的具體用法?Python pyb.Pin怎麽用?Python pyb.Pin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyb
的用法示例。
在下文中一共展示了pyb.Pin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def __init__(self, width=16, lines=2, pins=None, init=True):
"""Initialize instance and dictionary of output pin objects."""
# Initialize dict of pin objects
self.pins = {name: pyb.Pin(pin, PIN_MODE) for name, pin in
zip(PIN_NAMES, pins if pins else self._default_pins)}
# Maximum characters per line
self.width = width
# Number of display rows
self.lines = lines
# State of display on/off, underscore & blinking cursor control
self._displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
# State of text flow direction and auto-scrolling
self._displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
if init:
self.init()
示例2: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def __init__(self, path, trigger=None, uart="YA", baudrate=9600):
super().__init__(path)
self.button = "Scan QR code"
if simulator:
self.EOL = b"\r\n"
else:
self.EOL = b"\r"
self.data = b""
self.uart_bus = uart
self.uart = pyb.UART(uart, baudrate, read_buf_len=2048)
self.trigger = None
self.is_configured = False
if trigger is not None or simulator:
self.trigger = pyb.Pin(trigger, pyb.Pin.OUT)
self.trigger.on()
self.is_configured = True
self.scanning = False
示例3: init
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def init(self):
if self.is_configured:
return
# if failed to configure - probably a different scanner
# in this case fallback to PIN trigger mode FIXME
self.clean_uart()
self.is_configured = self.configure()
if self.is_configured:
print("Scanner: automatic mode")
return
# Try one more time with different baudrate
self.uart = pyb.UART(self.uart_bus, 115200, read_buf_len=2048)
self.clean_uart()
self.is_configured = self.configure()
if self.is_configured:
print("Scanner: automatic mode")
return
# PIN trigger mode
self.uart = pyb.UART(self.uart_bus, 9600, read_buf_len=2048)
self.trigger = pyb.Pin(QRSCANNER_TRIGGER, pyb.Pin.OUT)
self.trigger.on()
self.is_configured = True
print("Scanner: Pin trigger mode")
示例4: setup
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def setup():
global uart, gps # For shutdown
red = pyb.LED(1)
blue = pyb.LED(4)
sreader = asyncio.StreamReader(uart)
swriter = asyncio.StreamWriter(uart, {})
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
gps = GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=lambda *_: blue.toggle())
gps.FULL_CHECK = False
await asyncio.sleep(2)
await gps.baudrate(BAUDRATE)
uart.init(BAUDRATE)
await asyncio.sleep(1)
await gps.enable(gsa=0, gsv=0) # Disable satellite data
await gps.update_interval(UPDATE_INTERVAL)
pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
print(pstr.format(BAUDRATE, UPDATE_INTERVAL))
return gps
# Test terminator: task sets the passed event after the passed time.
示例5: us_setup
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def us_setup(tick):
global uart, gps # For shutdown
red = pyb.LED(1)
blue = pyb.LED(4)
sreader = asyncio.StreamReader(uart)
swriter = asyncio.StreamWriter(uart, {})
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
gps = GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=us_cb, pps_cb_args=(tick, blue))
gps.FULL_CHECK = False
await asyncio.sleep(2)
await gps.baudrate(BAUDRATE)
uart.init(BAUDRATE)
await asyncio.sleep(1)
await gps.enable(gsa=0, gsv=0) # Disable satellite data
await gps.update_interval(UPDATE_INTERVAL)
pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
print(pstr.format(BAUDRATE, UPDATE_INTERVAL))
示例6: setup
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def setup():
global uart, gps # For shutdown
red = pyb.LED(1)
blue = pyb.LED(4)
sreader = asyncio.StreamReader(uart)
swriter = asyncio.StreamWriter(uart, {})
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
gps = as_tGPS.GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=lambda *_: blue.toggle())
gps.FULL_CHECK = False
await asyncio.sleep(2)
await gps.baudrate(BAUDRATE)
uart.init(BAUDRATE)
await asyncio.sleep(1)
await gps.enable(gsa=0, gsv=0) # Disable satellite data
await gps.update_interval(UPDATE_INTERVAL)
pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
print(pstr.format(BAUDRATE, UPDATE_INTERVAL))
return gps
# Test terminator: task sets the passed event after the passed time.
示例7: us_setup
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def us_setup(tick):
global uart, gps # For shutdown
red = pyb.LED(1)
blue = pyb.LED(4)
sreader = asyncio.StreamReader(uart)
swriter = asyncio.StreamWriter(uart, {})
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
gps = as_tGPS.GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=us_cb, pps_cb_args=(tick, blue))
gps.FULL_CHECK = False
await asyncio.sleep(2)
await gps.baudrate(BAUDRATE)
uart.init(BAUDRATE)
await asyncio.sleep(1)
await gps.enable(gsa=0, gsv=0) # Disable satellite data
await gps.update_interval(UPDATE_INTERVAL)
pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
print(pstr.format(BAUDRATE, UPDATE_INTERVAL))
示例8: _power_off
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def _power_off(self): # turn of power and all signals
self.Pin_RESET.low()
self.Pin_PANEL_ON.low()
self.Pin_BORDER.low()
self.spi.deinit()
self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
self.Pin_SCK.low()
self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
self.Pin_MOSI.low()
# ensure SPI MOSI and CLOCK are Low before CS Low
self.Pin_EPD_CS.low()
# pulse discharge pin
self.Pin_DISCHARGE.high()
pyb.delay(150)
self.Pin_DISCHARGE.low()
# USER INTERFACE
# clear_screen() calls clear_data() and, if show, EPD_clear()
# showdata() called from show()
示例9: _power_off
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def _power_off(self): # turn of power and all signals
self.Pin_PANEL_ON.low()
# self._SPI_send(b'\x00\x00')
self.spi.deinit()
self.Pin_SCK.init(mode = pyb.Pin.OUT_PP)
self.Pin_SCK.low()
self.Pin_MOSI.init(mode = pyb.Pin.OUT_PP)
self.Pin_MOSI.low()
self.Pin_BORDER.low()
# ensure SPI MOSI and CLOCK are Low before CS Low
self.Pin_RESET.low()
self.Pin_EPD_CS.low()
# pulse discharge pin
self.Pin_DISCHARGE.high()
pyb.delay(150)
self.Pin_DISCHARGE.low()
# One frame of data is the number of lines * rows. For example:
# The 2.7” frame of data is 176 lines * 264 dots.
示例10: callBack
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def callBack(line):
print("Pin Interrupt!")
print("Line =", line)
示例11: foo
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def foo(p): # Toggle a pin when scheduled
print('start foo', p)
pin = pyb.Pin(p, pyb.Pin.OUT)
while True:
pin.value(1)
await asyncio.sleep(0)
pin.value(0)
await asyncio.sleep(0)
示例12: backlight
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def backlight(self, percent):
# deferred init of LED PIN
if self.pin_led is None:
# special treat for BG LED
self.pin_led = pyb.Pin("Y3", pyb.Pin.OUT_PP)
self.led_tim = pyb.Timer(4, freq=500)
self.led_ch = self.led_tim.channel(3, pyb.Timer.PWM, pin=self.pin_led)
percent = max(0, min(percent, 100))
self.led_ch.pulse_width_percent(percent) # set LED
#
# switch power on/off
#
示例13: __init__
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def __init__(self, controller = "XPT2046", asyn = False, *, confidence = 5, margin = 50, delay = 10, calibration = None):
if PCB_VERSION == 1:
self.pin_clock = pyb.Pin("Y8", pyb.Pin.OUT_PP)
self.pin_clock.value(0)
self.pin_d_out = pyb.Pin("Y7", pyb.Pin.OUT_PP)
self.pin_d_in = pyb.Pin("Y6", pyb.Pin.IN)
self.pin_irq = pyb.Pin("Y5", pyb.Pin.IN)
else:
self.pin_clock = pyb.Pin("X11", pyb.Pin.OUT_PP)
self.pin_clock.value(0)
self.pin_d_out = pyb.Pin("X12", pyb.Pin.OUT_PP)
self.pin_d_in = pyb.Pin("Y1", pyb.Pin.IN)
self.pin_irq = pyb.Pin("Y2", pyb.Pin.IN)
# set default values
self.ready = False
self.touched = False
self.x = 0
self.y = 0
self.buf_length = 0
cal = TOUCH.DEFAULT_CAL if calibration is None else calibration
self.asynchronous = False
self.touch_parameter(confidence, margin, delay, cal)
if asyn:
self.asynchronous = True
asyncio.create_task(self._main_thread())
# set parameters for get_touch()
# res: Resolution in bits of the returned values, default = 10
# confidence: confidence level - number of consecutive touches with a margin smaller than the given level
# which the function will sample until it accepts it as a valid touch
# margin: Difference from mean centre at which touches are considered at the same position
# delay: Delay between samples in ms.
#
示例14: low_power_pins
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def low_power_pins():
pins = [
# user IO pins
'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10', 'A11', 'A12', 'A13', 'A14', 'A15',
'B0', 'B1', 'B3', 'B4', 'B5', 'B7', 'B8', 'B9', 'B10', 'B11', 'B12', 'B13',
'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6',
'D0', 'D3', 'D8', 'D9',
'E0', 'E1', 'E12', 'E14', 'E15',
'F1', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F13', 'F14', 'F15',
'H2', 'H3', 'H5', 'H6', 'H7', 'H8',
'I0', 'I1',
# internal pins
'D1', 'D14', 'D15',
'F0', 'F12',
'G0', 'G1', 'G2', 'G3', 'G4', 'G5', #'G6',
'H4', 'H9', 'H10', 'H11', 'H12', 'H13', 'H14', 'H15',
'I2', 'I3',
]
pins_led = ['F3', 'F4', 'F5',]
pins_sdmmc = ['D6', 'D7', 'G9', 'G10', 'G11', 'G12']
pins_wlan = ['D2', 'D4', 'I7', 'I8', 'I9', 'I11']
pins_bt = ['D5', 'D10', 'E3', 'E4', 'E5', 'E6', 'G8', 'G13', 'G14', 'G15', 'I4', 'I5', 'I6', 'I10']
pins_qspi1 = ['B2', 'B6', 'D11', 'D12', 'D13', 'E2']
pins_qspi2 = ['E7', 'E8', 'E9', 'E10', 'E11', 'E13']
if disable_pins:
for p in pins:
pyb.Pin(p, pyb.Pin.IN, pyb.Pin.PULL_DOWN)
if disable_3v3:
pyb.Pin('EN_3V3', pyb.Pin.IN, None)
if disable_leds:
for p in pins_led:
pyb.Pin(p, pyb.Pin.IN, pyb.Pin.PULL_UP)
示例15: setup
# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Pin [as 別名]
def setup():
red = pyb.LED(1)
green = pyb.LED(2)
uart = pyb.UART(UART_ID, 9600, read_buf_len=200)
sreader = asyncio.StreamReader(uart)
pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
return GPS_Timer(sreader, pps_pin, local_offset=1,
fix_cb=lambda *_: red.toggle(),
pps_cb=lambda *_: green.toggle())
# Test terminator: task sets the passed event after the passed time.