Exemple #1
0
def main():
    '''
    Decode and draw jpg on display
    '''
    try:
        spi = SPI(1, SPI.MASTER, baudrate=42000000, prescaler=2)

        # initialize display
        tft = st7789.ST7789(spi,
                            240,
                            320,
                            reset=Pin('X3', Pin.OUT),
                            cs=Pin('X5', Pin.OUT),
                            dc=Pin('X4', Pin.OUT),
                            backlight=Pin('X2', Pin.OUT),
                            rotation=3)

        # enable display and clear screen
        tft.init()

        # display jpg
        tft.jpg("bigbuckbunny.jpg", 0, 0, st7789.SLOW)

    finally:
        # shutdown spi
        spi.deinit()
Exemple #2
0
def main():
    '''
    Draw on screen using map_bitarray_to_rgb565
    '''
    try:
        # initialize display spi port
        spi = SPI(1, SPI.MASTER, baudrate=42000000, prescaler=2)

        # configure display
        tft = st7789.ST7789(spi,
                            240,
                            320,
                            reset=Pin('X3', Pin.OUT),
                            cs=Pin('X5', Pin.OUT),
                            dc=Pin('X4', Pin.OUT),
                            backlight=Pin('X2', Pin.OUT),
                            rotation=3)

        # enable display and clear screen
        tft.init()
        tft.fill(st7789.BLACK)
        sprite = bytearray(512)

        # create pacman spites in random positions
        sprites = []
        for man in range(SPRITES):
            sprites.append(
                pacman(random.randint(0,
                                      tft.width() - SPRITE_WIDTH),
                       random.randint(0,
                                      tft.height() - SPRITE_HEIGHT),
                       random.randint(0, SPRITE_STEPS - 1)))

        # move and draw sprites
        while True:
            for man in sprites:
                # move the sprite
                man.move()

                # convert bitmap into rgb565 blitable buffer
                tft.map_bitarray_to_rgb565(SPRITE_BITMAPS[man.step], sprite,
                                           SPRITE_WIDTH, st7789.YELLOW,
                                           st7789.BLACK)

                # blit the buffer to the display
                tft.blit_buffer(sprite, man.x, man.y, SPRITE_WIDTH,
                                SPRITE_HEIGHT)

            time.sleep(0.1)

    finally:
        # shutdown spi
        spi.deinit()
Exemple #3
0
def main():
    '''
    Draw and move sprite
    '''
    try:
        spi = SPI(1, SPI.MASTER, baudrate=42000000, prescaler=2)

        # initialize display
        tft = st7789.ST7789(spi,
                            240,
                            320,
                            reset=Pin('X3', Pin.OUT),
                            cs=Pin('X5', Pin.OUT),
                            dc=Pin('X4', Pin.OUT),
                            backlight=Pin('X2', Pin.OUT),
                            rotation=3)

        # enable display and clear screen
        tft.init()
        tft.fill(st7789.BLACK)

        # create toast spites in random positions
        sprites = [
            toast(TOASTERS, 320 - 64, 0),
            toast(TOAST, 320 - 64 * 2, 80),
            toast(TOASTERS, 320 - 64 * 4, 160)
        ]

        # move and draw sprites
        while True:
            for man in sprites:
                bitmap = man.sprites[man.step]
                tft.fill_rect(man.x + bitmap.WIDTH - man.speed, man.y,
                              man.speed, bitmap.HEIGHT, st7789.BLACK)

                man.move()

                if man.x > 0:
                    tft.bitmap(bitmap, man.x, man.y)
                else:
                    tft.fill_rect(0, man.y, bitmap.WIDTH, bitmap.HEIGHT,
                                  st7789.BLACK)

            time.sleep(0.05)

    finally:
        # shutdown spi
        spi.deinit()
Exemple #4
0
print(spi)

spi = SPI(1, SPI.CONTROLLER)
spi = SPI(1, SPI.CONTROLLER, baudrate=500000)
spi = SPI(1,
          SPI.CONTROLLER,
          500000,
          polarity=1,
          phase=0,
          bits=8,
          firstbit=SPI.MSB,
          ti=False,
          crc=None)
print(str(spi)[:32], str(spi)[53:])  # don't print baudrate/prescaler

spi.init(SPI.PERIPHERAL, phase=1)
print(spi)
try:
    # need to flush input before we get an error (error is what we want to test)
    for i in range(10):
        spi.recv(1, timeout=100)
except OSError:
    print("OSError")

spi.init(SPI.CONTROLLER)
spi.send(1, timeout=100)
print(spi.recv(1, timeout=100))
print(spi.send_recv(1, timeout=100))

spi.deinit()
Exemple #5
0
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
    try:
        SPI(bus)
        print("SPI", bus)
    except ValueError:
        print("ValueError", bus)

spi = SPI(1)
print(spi)

spi = SPI(1, SPI.MASTER)
spi = SPI(1, SPI.MASTER, baudrate=500000)
spi = SPI(1, SPI.MASTER, 500000, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
print(spi)

spi.init(SPI.SLAVE, phase=1)
print(spi)
try:
    # need to flush input before we get an error (error is what we want to test)
    for i in range(10):
        spi.recv(1, timeout=100)
except OSError:
    print("OSError")

spi.init(SPI.MASTER)
spi.send(1, timeout=100)
print(spi.recv(1, timeout=100))
print(spi.send_recv(1, timeout=100))

spi.deinit()