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


Python machine.SPI属性代码示例

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


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

示例1: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Test code."""
    # Baud rate of 14500000 seems about the max
    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))

    # Build color list from all upper case constants (lazy approach)
    colors = [getattr(modules[__name__], name) for name in dir(
        modules[__name__]) if name.isupper() and name is not 'SPI']

    colors.sort()
    c = 0
    for x in range(1, 126, 25):
        for y in range(1, 126, 25):
            display.fill_rectangle(x, y, 25, 25, colors[c])
            c += 1
    sleep(9)
    display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:20,代码来源:demo_colored_squares.py

示例2: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Bouncing sprite."""
    try:
        # Baud rate of 14500000 seems about the max
        spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
        display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
        display.clear()

        # Load sprite
        logo = BouncingSprite('images/Python41x49.raw',
                              41, 49, 128, 128, 1, display)

        while True:
            timer = ticks_us()
            logo.update_pos()
            logo.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)

    except KeyboardInterrupt:
        display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:25,代码来源:demo_sprite.py

示例3: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Test code."""
    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
    display.contrast(0)
    display.draw_image('images/MicroPython128x128.raw',
                       0, 0, 128, 128)

    fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8)
    contrast_range = list(range(1, 16)) + list(reversed(range(15)))
    for c in contrast_range:
        display.contrast(c)
        display.draw_text(30, 120, 'contrast: {0:02d}'.format(c),
                          fixed_font, color565(255, 255, 255))
        sleep(1)

    display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:19,代码来源:demo_contrast.py

示例4: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Test code."""
    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))

    display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128)
    sleep(5)

    display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128)
    sleep(5)

    display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128)
    sleep(5)

    display.draw_image('images/Tortie128x128.raw', 0, 0, 128, 128)
    sleep(9)

    display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:20,代码来源:demo_images.py

示例5: spi_read

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def spi_read(self, size: int, **kwargs) -> str:
        """
        Read from an SPI bus.

        :param size: Number of bytes to read.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.spi_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        :return: String representation of the read bytes, or base64-encoded representation if the
            data can't be decoded to a string.
        """
        self.spi_open(**kwargs)
        code = 'spi.read({size})'.format(size=size)
        response = self.execute(code, **kwargs).output

        try:
            return response.decode()
        except UnicodeDecodeError:
            return base64.encodebytes(response).decode() 
开发者ID:BlackLight,项目名称:platypush,代码行数:20,代码来源:__init__.py

示例6: spi_write

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def spi_write(self, data: str, binary: bool = False, **kwargs):
        """
        Write data to an SPI bus.

        :param data: Data to be written.
        :param binary: By default data will be treated as a string. Set binary to True if it should
            instead be treated as a base64-encoded binary string to be decoded before being sent.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.spi_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        if binary:
            data = base64.decodebytes(data.encode())
        else:
            data = data.encode()

        data = 'b"' + ''.join(['\\x{:02x}'.format(b) for b in data]) + '"'
        self.spi_open(**kwargs)

        code = 'spi.write({data})'.format(data=data)
        self.execute(code, **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:22,代码来源:__init__.py

示例7: main

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def main():
    spi = machine.SPI(1, baudrate=40000000, polarity=1)
    display = st7789.ST7789(
        spi, 240, 240,
        reset=machine.Pin(5, machine.Pin.OUT),
        dc=machine.Pin(2, machine.Pin.OUT),
    )
    display.init()

    while True:
        display.fill(
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8),
            ),
        )
        # Pause 2 seconds.
        time.sleep(2) 
开发者ID:devbis,项目名称:st7789py_mpy,代码行数:21,代码来源:test_st7789.py

示例8: setup

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def setup(use_spi=False, soft=True):
    if use_spi:
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # X1    DC
        # X2    CS
        # X3    Rst
        # X6    CLK
        # X8    DATA
        pdc = machine.Pin('X1', machine.Pin.OUT_PP)
        pcs = machine.Pin('X2', machine.Pin.OUT_PP)
        prst = machine.Pin('X3', machine.Pin.OUT_PP)
        if soft:
            spi = machine.SPI(sck=machine.Pin('X6'), mosi=machine.Pin('X8'), miso=machine.Pin('X7'))
        else:
            spi = machine.SPI(1)
        ssd = SSD1306_SPI(WIDTH, HEIGHT, spi, pdc, prst, pcs)
    else:  # I2C
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # Y9    CLK
        # Y10   DATA
        if soft:
            pscl = machine.Pin('Y9', machine.Pin.OPEN_DRAIN)
            psda = machine.Pin('Y10', machine.Pin.OPEN_DRAIN)
            i2c = machine.I2C(scl=pscl, sda=psda)
        else:
            i2c = machine.I2C(2)
        ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
    return ssd 
开发者ID:peterhinch,项目名称:micropython-font-to-py,代码行数:34,代码来源:ssd1306_setup.py

示例9: setup

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def setup():
    pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
    pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
    prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
    spi = machine.SPI(1)
    ssd = SSD(spi, pcs, pdc, prst)  # Create a display instance
    return ssd 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:9,代码来源:test_colors.py

示例10: setup

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def setup():
    pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0)
    pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1)
    prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1)
    spi = machine.SPI(1)
    ssd = SSD(spi, pcs, pdc, prst, height=96)  # Create a display instance
    return ssd 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:9,代码来源:test_colors_96.py

示例11: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Bouncing box."""
    try:
        # Baud rate of 14500000 seems about the max
        spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
        display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
        display.clear()

        colors = [color565(255, 0, 0),
                  color565(0, 255, 0),
                  color565(0, 0, 255),
                  color565(255, 255, 0),
                  color565(0, 255, 255),
                  color565(255, 0, 255)]
        sizes = [12, 11, 10, 9, 8, 7]
        boxes = [Box(128, 128, sizes[i], display,
                 colors[i]) for i in range(6)]

        while True:
            timer = ticks_us()
            for b in boxes:
                b.update_pos()
                b.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)

    except KeyboardInterrupt:
        display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:32,代码来源:demo_bouncing_boxes.py

示例12: test

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def test():
    """Test code."""
    # Baud rate of 14500000 seems about the max
    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))

    c = 0
    for x in range(0, 128, 16):
        for y in range(0, 128, 16):
            color = color565(*hsv_to_rgb(c / 64, 1, 1))
            display.fill_circle(x + 7, y + 7, 7, color)
            c += 1
    sleep(9)
    display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:16,代码来源:demo_color_palette.py

示例13: spi_close

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def spi_close(self, **kwargs):
        """
        Turn off an SPI bus.

        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.spi_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        """
        self.spi_open(**kwargs)
        self.execute('spi.deinit()', **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:11,代码来源:__init__.py

示例14: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def __init__(self, spi, width, height, reset, dc, cs=None, backlight=None,
                 xstart=-1, ystart=-1):
        """
        display = st7789.ST7789(
            SPI(1, baudrate=40000000, phase=0, polarity=1),
            240, 240,
            reset=machine.Pin(5, machine.Pin.OUT),
            dc=machine.Pin(2, machine.Pin.OUT),
        )

        """
        self.width = width
        self.height = height
        self.spi = spi
        if spi is None:
            import machine
            self.spi = machine.SPI(1, baudrate=40000000, phase=0, polarity=1)
        self.reset = reset
        self.dc = dc
        self.cs = cs
        self.backlight = backlight
        if xstart >= 0 and ystart >= 0:
            self.xstart = xstart
            self.ystart = ystart
        elif (self.width, self.height) == (240, 240):
            self.xstart = 0
            self.ystart = 0
        elif (self.width, self.height) == (135, 240):
            self.xstart = 52
            self.ystart = 40
        else:
            raise ValueError(
                "Unsupported display. Only 240x240 and 135x240 are supported "
                "without xstart and ystart provided"
            ) 
开发者ID:devbis,项目名称:st7789py_mpy,代码行数:37,代码来源:st7789py.py

示例15: write

# 需要导入模块: import machine [as 别名]
# 或者: from machine import SPI [as 别名]
def write(self, command=None, data=None):
        """SPI write to the device: commands and data"""
        self.cs_low()
        if command is not None:
            self.dc_low()
            self.spi.write(bytes([command]))
        if data is not None:
            self.dc_high()
            self.spi.write(data)
        self.cs_high() 
开发者ID:devbis,项目名称:st7789py_mpy,代码行数:12,代码来源:st7789py.py


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