Ejemplo n.º 1
0
def main():
    '''
    Decode and draw the jpg on the display
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # initialize display
        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        # enable display and clear screen
        tft.init()

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

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 2
0
def main():
    '''
    Draw and move sprite
    '''
    try:

        # initialize display

        tft = ili9342c.ILI9342C(
            SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23)),
            320,
            240,
            reset=Pin(33, Pin.OUT),
            cs=Pin(14, Pin.OUT),
            dc=Pin(27, Pin.OUT),
            backlight=Pin(32, Pin.OUT),
            rotation=0,
            buffer_size=64*64*2)

        # enable display and clear screen
        tft.init()
        tft.fill(ili9342c.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,
                    ili9342c.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,
                        ili9342c.BLACK)

            time.sleep(0.05)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 3
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(
        2,
        baudrate=60000000,
        sck=Pin(18),
        mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(
        spi,
        320,
        240,
        reset=Pin(33, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(15, Pin.OUT),
        rotation=0)

    tft.init()
    tft.fill(ili9342c.BLACK)
    utime.sleep(1)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(ili9342c.BLUE)
            line = 0
            col = 0
            for char in range(font.FIRST, font.LAST):
                tft.text(
                    font,
                    chr(char),
                    col,
                    line,
                    ili9342c.WHITE,
                    ili9342c.BLUE)

                col += font.WIDTH
                if col > tft.width() - font.WIDTH:
                    col = 0
                    line += font.HEIGHT

                    if line > tft.height()-font.HEIGHT:
                        utime.sleep(3)
                        tft.fill(ili9342c.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
Ejemplo n.º 4
0
def main():
    '''
    Draw and move sprite
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # initialize display

        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        # enable display and clear screen
        tft.init()
        tft.fill(ili9342c.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, ili9342c.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,
                                  ili9342c.BLACK)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 5
0
def main():
    tft = ili9342c.ILI9342C(SPI(2,
                                baudrate=60000000,
                                polarity=1,
                                phase=1,
                                sck=Pin(18),
                                mosi=Pin(23)),
                            320,
                            240,
                            reset=Pin(33, Pin.OUT),
                            cs=Pin(14, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(32, Pin.OUT),
                            rotation=0,
                            buffer_size=16 * 32 * 2)

    tft.init()
    tft.fill(ili9342c.BLACK)
    utime.sleep(1)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(ili9342c.BLUE)
            line = 0
            col = 0
            for char in range(font.FIRST, font.LAST):

                tft.text(font, chr(char), col, line, ili9342c.WHITE,
                         ili9342c.BLUE)

                col += font.WIDTH
                if col > tft.width() - font.WIDTH:
                    col = 0
                    line += font.HEIGHT

                    if line > tft.height() - font.HEIGHT:
                        utime.sleep(3)
                        tft.fill(ili9342c.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
Ejemplo n.º 6
0
def main():
    '''
    Draw greetings on display cycling thru hershey fonts and colors
    '''
    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

        # Configure display
        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0)

        tft.init()
        tft.fill(ili9342c.BLACK)
        height = tft.height()
        width = tft.width()
        row = 0

        while True:
            row += 32
            tft.fill_rect(0, row - 16, width, 32, ili9342c.BLACK)
            tft.draw(next(FONTS), next(GREETINGS), 0, row, next(COLORS))

            if row > 192:
                row = 0

            utime.sleep(0.25)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 7
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(spi,
                            320,
                            240,
                            reset=Pin(33, Pin.OUT),
                            cs=Pin(5, Pin.OUT),
                            dc=Pin(15, Pin.OUT),
                            rotation=0)

    tft.init()
    tft.fill(ili9342c.BLACK)
    time.sleep(1)

    while True:
        for rotation in range(4):
            tft.rotation(rotation)
            tft.fill(0)
            col_max = tft.width() - font.WIDTH * 6
            row_max = tft.height() - font.HEIGHT

            for _ in range(1000):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    ili9342c.color565(random.getrandbits(8),
                                      random.getrandbits(8),
                                      random.getrandbits(8)),
                    ili9342c.color565(random.getrandbits(8),
                                      random.getrandbits(8),
                                      random.getrandbits(8)))
Ejemplo n.º 8
0
def main():

    try:
        # Turn display power
        axp = axp202c.PMU(address=0x34)
        axp.enablePower(axp202c.AXP192_LDO2)
        # Set backlight voltage
        axp.setDC3Voltage(3000)

        spi = SPI(2,
                  baudrate=20000000,
                  sck=Pin(18),
                  miso=Pin(38),
                  mosi=Pin(23))

        # initialize and mount the sdcard
        sd_device = sdcard.SDCard(spi, cs=Pin(4), baudrate=20000000)
        uos.mount(sd_device, '/sd')

        # initialize display

        tft = ili9342c.ILI9342C(spi,
                                320,
                                240,
                                cs=Pin(5, Pin.OUT),
                                dc=Pin(15, Pin.OUT),
                                rotation=0,
                                buffer_size=38400)

        tft.init()

        for i in range(1, 2387):
            frame = "/sd/160x120/{:04d}.jpg".format(i)
            tft.jpg(frame, 80, 60, ili9342c.FAST)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 9
0
def main():
    '''
    Draw greetings on display cycling thru hershey fonts and colors
    '''
    try:
        tft = ili9342c.ILI9342C(SPI(2,
                                    baudrate=60000000,
                                    sck=Pin(18),
                                    mosi=Pin(23)),
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(14, Pin.OUT),
                                dc=Pin(27, Pin.OUT),
                                backlight=Pin(32, Pin.OUT),
                                rotation=0)

        tft.init()
        tft.fill(ili9342c.BLACK)
        height = tft.height()
        width = tft.width()
        row = 0

        while True:
            row += 32
            color = next(COLORS)
            tft.fill_rect(0, row - 16, width, 32, ili9342c.BLACK)
            tft.draw(next(FONTS), next(GREETINGS), 0, row, color)

            if row > 192:
                row = 0

            utime.sleep(0.25)

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 10
0
def main():
    tft = ili9342c.ILI9342C(SPI(2,
                                baudrate=60000000,
                                sck=Pin(18),
                                mosi=Pin(23)),
                            320,
                            240,
                            reset=Pin(33, Pin.OUT),
                            cs=Pin(14, Pin.OUT),
                            dc=Pin(27, Pin.OUT),
                            backlight=Pin(32, Pin.OUT),
                            rotation=0,
                            buffer_size=16 * 16 * 2)

    colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
    foreground = next(colors)
    background = ili9342c.BLACK

    tft.init()
    tft.fill(background)
    utime.sleep(1)

    height = tft.height()
    width = tft.width()
    last_line = height - font.HEIGHT

    tfa = 0  # top free area
    tfb = 0  # bottom free area
    tft.vscrdef(tfa, height, tfb)

    scroll = 0
    character = 0

    while True:
        # clear top line before scrolling off display
        tft.fill_rect(0, scroll, width, 1, background)

        # Write new line when we have scrolled the height of a character
        if scroll % font.HEIGHT == 0:
            line = (scroll + last_line) % height

            # write character hex value as a string
            tft.text(font, 'x{:02x}'.format(character), 16, line, foreground,
                     background)

            # write character using a integer (could be > 0x7f)
            tft.text(font, character, 90, line, foreground, background)

            # change color for next line
            foreground = next(colors)

            # next character with rollover at 256
            character += 1
            character %= 256

        # scroll the screen up 1 row
        tft.vscsad(scroll + tfa)
        scroll += 1
        scroll %= height

        utime.sleep(0.01)
Ejemplo n.º 11
0
def main():
    '''
    Draw on screen using map_bitarray_to_rgb565
    '''
    try:

        # initialize display

        tft = ili9342c.ILI9342C(SPI(2,
                                    baudrate=60000000,
                                    polarity=1,
                                    phase=1,
                                    sck=Pin(18),
                                    mosi=Pin(23)),
                                320,
                                240,
                                reset=Pin(33, Pin.OUT),
                                cs=Pin(14, Pin.OUT),
                                dc=Pin(27, Pin.OUT),
                                backlight=Pin(32, Pin.OUT),
                                rotation=0,
                                buffer_size=16 * 16 * 2)

        # enable display and clear screen
        tft.init()
        tft.fill(ili9342c.BLACK)
        time.sleep(1)

        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, ili9342c.YELLOW,
                                           ili9342c.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
        if 'spi' in locals():
            spi.deinit()
Ejemplo n.º 12
0
def main():
    # Turn display power
    axp = axp202c.PMU(address=0x34)
    axp.enablePower(axp202c.AXP192_LDO2)
    # Set backlight voltage
    axp.setDC3Voltage(3000)

    spi = SPI(
        2,
        baudrate=60000000,
        sck=Pin(18),
        mosi=Pin(23))

    # initialize display

    tft = ili9342c.ILI9342C(
        spi,
        320,
        240,
        reset=Pin(33, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(15, Pin.OUT),
        rotation=0)

    colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
    foreground = next(colors)
    background = ili9342c.BLACK

    tft.init()
    tft.fill(background)
    utime.sleep(1)

    height = tft.height()
    width = tft.width()
    last_line = height - font.HEIGHT

    tfa = 0        # top free area
    tfb = 0        # bottom free area
    tft.vscrdef(tfa, height, tfb)

    scroll = 0
    character = 32

    while True:
        # clear top line before scrolling off display
        tft.fill_rect(0, scroll, width, 1, background)

        # Write new line when we have scrolled the height of a character
        if scroll % font.HEIGHT == 0:
            line = (scroll + last_line) % height

            # write character hex value as a string
            tft.text(
                font,
                'x{:02x}'.format(character),
                16,
                line,
                foreground,
                background)

            # write character using a integer (could be > 0x7f)
            tft.text(
                font,
                character,
                90,
                line,
                foreground,
                background)

            # change color for next line
            foreground = next(colors)

            # next character with rollover at 256
            character += 1
            if character > 127:
                character = 32

        # scroll the screen up 1 row
        tft.vscsad(scroll+tfa)
        scroll += 1
        scroll %= height

        utime.sleep(0.01)