コード例 #1
0
def main():
    spi = machine.SPI(1,
                      baudrate=8000000,
                      polarity=1,
                      phase=1,
                      sck=Pin(18, Pin.OUT, Pin.PULL_DOWN),
                      mosi=Pin(23, Pin.OUT, Pin.PULL_UP),
                      miso=Pin(19, Pin.IN, Pin.PULL_UP))
    display = st7789.ST7789(
        spi,
        240,
        240,
        reset=Pin(2, machine.Pin.OUT, Pin.PULL_UP),
        dc=Pin(4, machine.Pin.OUT, Pin.PULL_UP),
    )
    display.init()
    display.fill(st7789.color565(128, 128, 255))
    graphics = gfx.GFX(240, 240, display.pixel)
    graphics.fill_rect(50, 50, 50, 50, st7789.color565(0, 0, 0))
    print(mem_free())
    collect()
    print(mem_free())
    while True:
        display.fill(
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8),
            ), )
        # Pause 2 seconds.
        time.sleep(0.5)
コード例 #2
0
ファイル: test_st7789.py プロジェクト: emard/st7789py_mpy
def main():
    gpio_csn = const(17)
    gpio_resn = const(26)
    gpio_dc = const(16)
    gpio_sck = const(14)
    gpio_mosi = const(15)
    gpio_miso = const(2)
    spi = machine.SPI(-1,
                      baudrate=40000000,
                      polarity=1,
                      sck=machine.Pin(gpio_sck),
                      mosi=machine.Pin(gpio_mosi),
                      miso=machine.Pin(gpio_miso))
    display = st7789.ST7789(
        spi,
        240,
        240,
        reset=machine.Pin(gpio_resn, machine.Pin.OUT),
        dc=machine.Pin(gpio_dc, 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)
コード例 #3
0
    def run(self):
        print("st7789")
        # NOTE 7-pin display doesn't have miso and cs pins
        spi = SPI(2,
                  baudrate=26000000,
                  polarity=1,
                  mosi=Pin(25),
                  sck=Pin(17),
                  miso=Pin(33))
        self.display = st7789.ST7789(spi,
                                     240,
                                     240,
                                     reset=Pin(16, Pin.OUT),
                                     dc=Pin(26, Pin.OUT),
                                     xstart=0,
                                     ystart=320 - 240)
        self.display.init()
        vf = vectorfont.vectorfont(240, 240, self.line)

        while True:
            self.display.fill(st7789.color565(0, 0, 0))
            vf.text("123ABCdef", 0, 120, spacing=20, xscale=1024, yscale=1024)
            for i in range(100):
                self.display.line(120,120,randint(0,240),randint(0,240), \
                  st7789.color565(
                      getrandbits(8),
                      getrandbits(8),
                      getrandbits(8),
                  )
                )
            time.sleep(2)
コード例 #4
0
def test_main(filename):
  back=machine.Pin(5, machine.Pin.OUT)
  back.value(1)
  spi = SPI(1, baudrate=40000000, polarity=1, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))#HSPI
  display = st7789.ST7789(
        spi, 240, 240,
        reset=machine.Pin(21, machine.Pin.OUT),
        dc=machine.Pin(22, machine.Pin.OUT),
        cs=machine.Pin(15, machine.Pin.OUT),
        backlight=machine.Pin(5, machine.Pin.OUT),
  )
  display.init()
  
  display.fill(
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8),
            ),
  )
  # Pause 2 seconds.
  time.sleep(2)
  
  f=open(filename, 'rb')  #Read binary files
  if f.read(2) == b'BM':  #header
    dummy = f.read(8) #file size(4), creator bytes(4)
    offset = int.from_bytes(f.read(4), 'little')
    hdrsize = int.from_bytes(f.read(4), 'little')
    width = int.from_bytes(f.read(4), 'little')
    height = int.from_bytes(f.read(4), 'little')
    if int.from_bytes(f.read(2), 'little') == 1: #planes must be 1
        depth = int.from_bytes(f.read(2), 'little')
        if depth == 24 and int.from_bytes(f.read(4), 'little') == 0:#compress method == uncompressed
            print("Image size:", width, "x", height)
            rowsize = (width * 3 + 3) & ~3
            if height < 0:
                height = -height
                flip = False
            else:
                flip = True
            w, h = width, height
            if w > 240: w = 240
            if h > 240: h = 240
            #tft._setwindowloc((0,0),(w - 1,h - 1))
            display.set_window(0,0,(w - 1),(h - 1))
            for row in range(h):
                if flip:
                    pos = offset + (height - 1 - row) * rowsize
                else:
                    pos = offset + row * rowsize
                if f.tell() != pos:
                    dummy = f.seek(pos)
                for col in range(w):
                    bgr = f.read(3)

                    aColor=st7789.color565(bgr[2], bgr[1], bgr[0])
                    colorData = bytearray(2)
                    colorData[0] = aColor >> 8
                    colorData[1] = aColor
                    display.write(None, colorData)
コード例 #5
0
def main():
    spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))

    tft = st7789.ST7789(
        spi,
        320,
        240,
        reset=Pin(4, Pin.OUT),
        cs=Pin(13, Pin.OUT),
        dc=Pin(12, Pin.OUT),
        backlight=Pin(15, Pin.OUT),
        rotation=0)

    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(100):
                tft.text(
                    font,
                    "Hello!",
                    random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8)),
                    st7789.color565(
                        random.getrandbits(8),
                        random.getrandbits(8),
                        random.getrandbits(8))
                )
コード例 #6
0
ファイル: ttgo_lines.py プロジェクト: russhughes/st7789py_mpy
def main():
    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(18),
                  mosi=Pin(19),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=0)

    tft.fill(st7789.BLACK)

    while True:
        tft.line(
            random.randint(0, tft.width), random.randint(0, tft.height),
            random.randint(0, tft.width), random.randint(0, tft.height),
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))

        width = random.randint(0, tft.width // 2)
        height = random.randint(0, tft.height // 2)
        col = random.randint(0, tft.width - width)
        row = random.randint(0, tft.height - height)
        tft.fill_rect(
            col, row, width, height,
            st7789.color565(random.getrandbits(8), random.getrandbits(8),
                            random.getrandbits(8)))
コード例 #7
0
def main():
    spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))

    tft = st7789.ST7789(spi,
                        320,
                        240,
                        reset=Pin(4, Pin.OUT),
                        cs=Pin(13, Pin.OUT),
                        dc=Pin(12, Pin.OUT),
                        backlight=Pin(15, Pin.OUT),
                        rotation=0)

    tft.vscrdef(40, 240, 40)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(st7789.BLUE)
            line = 0
            col = 0

            for char in range(font.FIRST, font.LAST):
                tft.text(font, chr(char), col, line, st7789.WHITE, st7789.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(st7789.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
コード例 #8
0
ファイル: chango.py プロジェクト: russhughes/st7789py_mpy
def main():
    # enable display and clear screen
    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(18),
                  mosi=Pin(19),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=1)

    tft.fill(st7789.BLACK)

    row = 0
    tft.write(font_16, "abcdefghijklmnopqrst", 0, row, st7789.RED)
    row += font_16.HEIGHT

    tft.write(font_32, "abcdefghij", 0, row, st7789.GREEN)
    row += font_32.HEIGHT

    tft.write(font_64, "abcd", 0, row, st7789.BLUE)
    row += font_64.HEIGHT
コード例 #9
0
ファイル: ttgo_hello.py プロジェクト: yoyojacky/st7789py_mpy
def main():
    tft = st7789.ST7789(SPI(2,
                            baudrate=30000000,
                            polarity=1,
                            phase=1,
                            sck=Pin(18),
                            mosi=Pin(19)),
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=0)

    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(100):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)))
コード例 #10
0
def main():
    # ESP 8266 SCK D5, MOSI D7
    # ESP32 SCK
    spi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
    tft = st7789.ST7789(spi,
                        240,
                        240,
                        reset=Pin(27, Pin.OUT),
                        dc=Pin(26, Pin.OUT),
                        backlight=Pin(25, Pin.OUT),
                        rotation=0)
    """
    tft = st7789.ST7789(spi, 240, 240,
        # D0, 16
        reset=Pin(27, Pin.OUT),
        # D4. Though NA for my board. Assign to D4 to make program happy. Don't connect.
        cs=Pin(2, Pin.OUT),
        # D1, 5
        dc=Pin(26, Pin.OUT),
        # D2, 4
        backlight=Pin(25, Pin.OUT),
        rotation=0) """

    tft.fill(0)
    tft.line(0, 0, 100, 100, st7789.color565(200, 0, 0))
コード例 #11
0
ファイル: noto_fonts.py プロジェクト: russhughes/st7789py_mpy
def main():

    def center(font, string, row, color=st7789.WHITE):
        screen = tft.width                        # get screen width
        width = tft.write_width(font, string)     # get the width of the string
        if width and width < screen:              # if the string < display
            col = tft.width // 2 - width // 2     # find the column to center
        else:                                     # otherwise
            col = 0                               # left justify

        tft.write(font, string, col, row, color)  # and write the string

    try:
        spi = SoftSPI(
            baudrate=20000000,
            polarity=1,
            phase=0,
            sck=Pin(18),
            mosi=Pin(19),
            miso=Pin(13))

        tft = st7789.ST7789(
            spi,
            135,
            240,
            reset=Pin(23, Pin.OUT),
            cs=Pin(5, Pin.OUT),
            dc=Pin(16, Pin.OUT),
            backlight=Pin(4, Pin.OUT),
            rotation=1)

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

        row = 16

        # center the name of the first font, using the font
        center(noto_sans, "NotoSans", row, st7789.RED)
        row += noto_sans.HEIGHT

        # center the name of the second font, using the font
        center(noto_serif, "NotoSerif", row, st7789.GREEN)
        row += noto_serif.HEIGHT

        # center the name of the third font, using the font
        center(noto_mono, "NotoSansMono", row, st7789.BLUE)
        row += noto_mono.HEIGHT

    finally:
        # shutdown spi
        if 'spi' in locals():
            spi.deinit()
コード例 #12
0
ファイル: lines.py プロジェクト: russhughes/st7789py_mpy
def main():
    # configure display

    spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))

    tft = st7789.ST7789(
        spi,
        320,
        240,
        reset=Pin(4, Pin.OUT),
        cs=Pin(13, Pin.OUT),
        dc=Pin(12, Pin.OUT),
        backlight=Pin(15, Pin.OUT),
        rotation=0)

    tft.fill(st7789.BLUE)

    while True:
        tft.line(
            random.randint(0, tft.width),
            random.randint(0, tft.height),
            random.randint(0, tft.width),
            random.randint(0, tft.height),
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8)
                )
            )

        width = random.randint(0, tft.width // 2)
        height = random.randint(0, tft.height // 2)
        col = random.randint(0, tft.width - width)
        row = random.randint(0, tft.height - height)
        tft.fill_rect(
            col,
            row,
            width,
            height,
            st7789.color565(
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8)
            )
        )
コード例 #13
0
ファイル: scroll.py プロジェクト: russhughes/st7789py_mpy
def main():
    Pin(22, Pin.OUT, value=1)

    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(2),
                  mosi=Pin(3),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(0, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(1, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=0)

    last_line = tft.height - font.HEIGHT
    tfa = 40
    tfb = 40
    tft.vscrdef(tfa, 240, tfb)

    tft.fill(st7789.BLUE)
    scroll = 0
    character = 0
    while True:
        tft.fill_rect(0, scroll, tft.width, 1, st7789.BLUE)

        if scroll % font.HEIGHT == 0:
            tft.text(font, '\\x{:02x}= {:s} '.format(character,
                                                     chr(character)), 0,
                     (scroll + last_line) % tft.height, st7789.WHITE,
                     st7789.BLUE)

            character = character + 1 if character < 256 else 0

        tft.vscsad(scroll + tfa)
        scroll += 1

        if scroll == tft.height:
            scroll = 0

        utime.sleep(0.01)
コード例 #14
0
def main():
    #spi = machine.SPI(1, baudrate=40000000, phase=0, polarity=1)
    spi = machine.SPI(1, baudrate=8000000, polarity=1, phase=0)
    display = st7789.ST7789(
        spi,
        240,
        240,
        reset=machine.Pin(16, 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),
            ), )
コード例 #15
0
ファイル: test_st7789.py プロジェクト: timm-zz/st7789py_mpy
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)
コード例 #16
0
ファイル: toasters.py プロジェクト: russhughes/st7789py_mpy
def main():
    """
    Initialize the display and draw flying toasters and toast
    """
    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(18),
                  mosi=Pin(19),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=0)

    tft.fill(st7789.BLACK)
    # create toast spites in random positions
    sprites = [
        toast(TOASTERS, 135 - 64, 0),
        toast(TOAST, 135 - 64 * 2, 80),
        toast(TOASTERS, 135 - 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)
コード例 #17
0
ファイル: fonts.py プロジェクト: russhughes/st7789py_mpy
def main():
    Pin(22, Pin.OUT, value=1)

    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(2),
                  mosi=Pin(3),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(0, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(1, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=0)

    tft.vscrdef(40, 240, 40)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(st7789.BLUE)
            line = 0
            col = 0

            for char in range(font.FIRST, font.LAST):
                tft.text(font, chr(char), col, line, st7789.WHITE, st7789.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(st7789.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
コード例 #18
0
def main():
    backlight = Pin(4, Pin.OUT)
    backlight.value(1)

    tft = st7789.ST7789(SPI(2,
                            baudrate=30000000,
                            polarity=1,
                            phase=1,
                            sck=Pin(18),
                            mosi=Pin(19)),
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=backlight,
                        rotation=0)

    tft.vscrdef(40, 240, 40)

    while True:
        for font in (font1, font2, font3, font4):
            tft.fill(st7789.BLUE)
            line = 0
            col = 0

            for char in range(font.FIRST, font.LAST):
                tft.text(font, chr(char), col, line, st7789.WHITE, st7789.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(st7789.BLUE)
                        line = 0
                        col = 0

            utime.sleep(3)
コード例 #19
0
ファイル: ttgo_scroll.py プロジェクト: yoyojacky/st7789py_mpy
def main():
    tft = st7789.ST7789(
        SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
        135,
        240,
        reset=Pin(23, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(16, Pin.OUT),
        backlight=Pin(4, Pin.OUT),
        rotation=0)

    last_line = tft.height - font.HEIGHT
    tfa = 40
    tfb = 40
    tft.vscrdef(tfa, 240, tfb)

    tft.fill(st7789.BLUE)
    scroll = 0
    counter = 0
    while True:
        tft.fill_rect(0,scroll, tft.width, 1, st7789.BLUE)

        if scroll % font.HEIGHT == 0:
            counter += 1
            tft.text(
                font,
                str(counter),
                0,
                (scroll + last_line) % tft.height,
                st7789.WHITE,
                st7789.BLUE)

        tft.vscsad(scroll+tfa)
        scroll +=1

        if scroll == tft.height:
            scroll = 0

        utime.sleep(0.005)
コード例 #20
0
def init():
    bl = machine.Pin(4, machine.Pin.OUT)
    bl.on()

    spi = machine.SPI(2,
                      baudrate=30000000,
                      polarity=1,
                      phase=1,
                      sck=machine.Pin(18),
                      mosi=machine.Pin(19))

    global display

    display = st7789.ST7789(spi,
                            135,
                            240,
                            reset=machine.Pin(23, machine.Pin.OUT),
                            cs=machine.Pin(5, machine.Pin.OUT),
                            dc=machine.Pin(16, machine.Pin.OUT))

    display.init()
    clear()
コード例 #21
0
ファイル: scroll.py プロジェクト: russhughes/st7789py_mpy
def main():
    spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))

    tft = st7789.ST7789(spi,
                        320,
                        240,
                        reset=Pin(4, Pin.OUT),
                        cs=Pin(13, Pin.OUT),
                        dc=Pin(12, Pin.OUT),
                        backlight=Pin(15, Pin.OUT),
                        rotation=0)

    last_line = tft.height - font.HEIGHT
    tfa = 0
    tfb = 0
    tft.vscrdef(tfa, 240, tfb)

    tft.fill(st7789.BLUE)
    scroll = 0
    character = 0
    while True:
        tft.fill_rect(0, scroll, tft.width, 1, st7789.BLUE)

        if scroll % font.HEIGHT == 0:
            tft.text(font, '\\x{:02x}= {:s} '.format(character,
                                                     chr(character)), 0,
                     (scroll + last_line) % tft.height, st7789.WHITE,
                     st7789.BLUE)

            character = character + 1 if character < 256 else 0

        tft.vscsad(scroll + tfa)
        scroll += 1

        if scroll == tft.height:
            scroll = 0

        utime.sleep(0.01)
コード例 #22
0
ファイル: hello.py プロジェクト: russhughes/st7789py_mpy
def main():
    Pin(22, Pin.OUT, value=1)

    spi = SoftSPI(baudrate=20000000,
                  polarity=1,
                  phase=0,
                  sck=Pin(2),
                  mosi=Pin(3),
                  miso=Pin(13))

    tft = st7789.ST7789(spi,
                        135,
                        240,
                        reset=Pin(0, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(1, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=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(100):
                tft.text(
                    font, "Hello!", random.randint(0, col_max),
                    random.randint(0, row_max),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)),
                    st7789.color565(random.getrandbits(8),
                                    random.getrandbits(8),
                                    random.getrandbits(8)))
コード例 #23
0
import random

import machine
import st7789py as st7789
import time

spi = machine.SPI(1,
                  baudrate=10000000,
                  polarity=1,
                  sck=machine.Pin(18),
                  miso=machine.Pin(19),
                  mosi=machine.Pin(23))
display = st7789.ST7789(
    spi,
    240,
    240,
    reset=machine.Pin(5, machine.Pin.OUT),
    dc=machine.Pin(15, machine.Pin.OUT),
)
display.init()

while (1):
    display.fill(
        st7789.color565(
            random.getrandbits(8),
            random.getrandbits(8),
            random.getrandbits(8),
        ), )
    time.sleep(2)
コード例 #24
0
def main():
    #Import fonts we'll be using
    from fonts import vga2_8x8 as smallfont
    from fonts import vga2_bold_16x16 as bigfont
    from fonts import vga2_bold_16x32 as biggestfont

    #Initialize the display
    tft = st7789.ST7789(SPI(2,
                            baudrate=30000000,
                            polarity=1,
                            phase=1,
                            sck=Pin(18),
                            mosi=Pin(19)),
                        135,
                        240,
                        reset=Pin(23, Pin.OUT),
                        cs=Pin(5, Pin.OUT),
                        dc=Pin(16, Pin.OUT),
                        backlight=Pin(4, Pin.OUT),
                        rotation=1)

    #Print init message to serial and display
    print("Corona tracker v1.2, Dex&Delly&Meow&jklk 03/2020")
    tft.text(smallfont, "Corona tracker v1.2", 5, 5,
             st7789.color565(255, 255, 255), st7789.color565(0, 0, 0))
    tft.text(smallfont, "Dex&Delly&Meow&jklk 03/2020", 5, 20,
             st7789.color565(255, 255, 255), st7789.color565(0, 0, 0))

    #Connect to WLAN
    netConnect()

    #Display loop
    import time
    apiUpdateIn = 0
    while True:
        if apiUpdateIn == 0:
            #Get API data (only once every 10 refreshes)
            inJson = getWebData()
            print("API Data retrieved!")

            countTested = inJson['totalTested']
            countInfected = inJson['infected']
            countRecovered = inJson['recovered']
            countDead = inJson['dead']
            lastUpdate = inJson['lastUpdatedAtSource'].replace("T",
                                                               " ").replace(
                                                                   "Z", "")
            infectedPrague = inJson['infectedPrague']
            apiUpdateIn = 10
            del inJson

        else:
            apiUpdateIn = apiUpdateIn - 1

        #Clear the screen
        tft.fill(0)

        #Basic info
        if apiUpdateIn % 2 == 0:
            #Only numbers (better visibility)
            tft.text(biggestfont, alignValue(countInfected, 5, -1), 5, 5,
                     st7789.color565(255, 255, 255),
                     st7789.color565(170, 170, 0))

            tft.text(biggestfont, alignValue(countDead, 4, 0), 95, 5,
                     st7789.color565(255, 255, 255),
                     st7789.color565(170, 0, 0))

            tft.text(biggestfont, alignValue(countRecovered, 4, 1), 170, 5,
                     st7789.color565(255, 255, 255),
                     st7789.color565(0, 170, 0))

            tft.text(biggestfont, alignValue(infectedPrague, 5, -1), 5, 35,
                     st7789.color565(255, 255, 255),
                     st7789.color565(150, 140, 0))

        else:
            #Full description (smaller text)
            tft.text(bigfont, "Infected: " + str(countInfected), 5, 5,
                     st7789.color565(255, 255, 255),
                     st7789.color565(170, 170, 0))

            tft.text(bigfont, "Dead: " + str(countDead), 5, 25,
                     st7789.color565(255, 255, 255),
                     st7789.color565(170, 0, 0))

            tft.text(bigfont, "Recovered: " + str(countRecovered), 5, 45,
                     st7789.color565(255, 255, 255),
                     st7789.color565(0, 170, 0))

        #Other info
        tft.text(bigfont, "Tested: " + str(countTested), 5, 65,
                 st7789.color565(255, 255, 255), st7789.color565(0, 0, 170))

        tft.text(smallfont, "Last Update: " + str(lastUpdate), 5, 90,
                 st7789.color565(255, 255, 255), st7789.color565(0, 0, 0))

        tft.text(smallfont, "Dex&Delly&Meow&jklk 03/2020", 5, 105,
                 st7789.color565(255, 255, 255), st7789.color565(0, 0, 0))

        #Refresh display every 10s
        time.sleep(10)
bl = machine.Pin(5, machine.Pin.OUT)
bl.value(1)

spi = machine.SPI(1,
                  baudrate=80000000,
                  polarity=1,
                  phase=0,
                  sck=machine.Pin(14),
                  mosi=machine.Pin(13),
                  miso=machine.Pin(12))  #HSPI

display = st7789.ST7789(
    spi,
    240,
    240,
    reset=machine.Pin(21, machine.Pin.OUT),
    dc=machine.Pin(22, machine.Pin.OUT),
    cs=machine.Pin(15, machine.Pin.OUT),
    backlight=machine.Pin(5, machine.Pin.OUT),
)
display.init()  #initialize
display.fill(st7789.BLACK)

row = 0
again = True
try:
    while again:
        #Set RGB565 random color
        color = st7789.color565(random.getrandbits(8), random.getrandbits(8),
                                random.getrandbits(8))
コード例 #26
0
ファイル: feathers.py プロジェクト: russhughes/st7789py_mpy
def main():
    '''
    The big show!
    '''
    #enable display and clear screen

    tft = st7789.ST7789(SoftSPI(baudrate=30000000,
                                polarity=1,
                                sck=Pin(10),
                                mosi=Pin(11),
                                miso=Pin(16)),
                        135,
                        240,
                        reset=Pin(12, Pin.OUT),
                        cs=Pin(9, Pin.OUT),
                        dc=Pin(8, Pin.OUT),
                        backlight=Pin(13, Pin.OUT),
                        rotation=1)

    tft.fill(st7789.BLACK)  # clear screen

    height = tft.height  # height of display in pixels
    width = tft.width  # width if display in pixels

    tfa = 40  # top free area when scrolling
    bfa = 40  # bottom free area when scrolling

    scroll = 0  # scroll position
    wheel = 0  # color wheel position

    tft.vscrdef(tfa, width, bfa)  # set scroll area
    tft.vscsad(scroll + tfa)  # set scroll position
    tft.fill(st7789.BLACK)  # clear screen

    half = (height >> 1) - 1  # half the height of the dislay
    interval = 0  # steps between new points
    increment = 0  # increment per step
    counter = 1  # step counter, overflow to start
    current_y = 0  # current_y value (right point)
    last_y = 0  # last_y value (left point)

    # segment offsets
    x_offsets = [x * (width // 8) - 1 for x in range(2, 9)]

    while True:
        # when the counter exceeds the interval, save current_y to last_y,
        # choose a new random value for current_y between 0 and 1/2 the
        # height of the display, choose a new random interval then reset
        # the counter to 0

        if counter > interval:
            last_y = current_y
            current_y = random.randint(0, half)
            counter = 0
            interval = random.randint(10, 100)
            increment = 1 / interval  # increment per step

        # clear the first column of the display and scroll it
        tft.vline(scroll, 0, height, st7789.BLACK)
        tft.vscsad(scroll + tfa)

        # get the next point between last_y and current_y
        tween = int(between(last_y, current_y, counter * increment))

        # draw mirrored pixels across the display at the offsets using the color_wheel effect
        for i, x_offset in enumerate(x_offsets):
            tft.pixel((scroll + x_offset) % width, half + tween,
                      color_wheel(wheel + (i << 2)))
            tft.pixel((scroll + x_offset) % width, half - tween,
                      color_wheel(wheel + (i << 2)))

        # increment scroll, counter, and wheel
        scroll = (scroll + 1) % width
        wheel = (wheel + 1) % 256
        counter += 1
コード例 #27
0
ファイル: spi_240x240.py プロジェクト: das-labor/badge-2021
led_state = False

spi = SPI(
   1,
   baudrate=40000000,
   polarity=1,
   phase=0,
   sck=Pin(14),
   mosi=Pin(13),
   miso=Pin(12)
)

dc    = Pin(16, Pin.OUT)
reset = Pin(17, Pin.OUT)

display = st7789py.ST7789(spi, 240, 240, reset=reset, dc=dc)

print("SPI TFT display init")
display.init()

while True:
    # TODO: GPIO pins 34-39 do not have a pull-up resistor :(
    # see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html
    #if not button_A.value():
    #    display.fill_rect(50, 70, 25, 25, st7789py.YELLOW)
    #    print("Button A")

    if not button_B.value():
        display.fill_rect(80, 110, 35, 75, st7789py.BLUE)
        print("Button B")
        led_state = not led_state
コード例 #28
0
#sta_if.connect("NTA2019", "notroll2019")

gpios = [32, 33, 25]
pins = [Pin(i, Pin.OUT) for i in gpios]

Pin(4, Pin.OUT).value(1)

spi = SPI(2, sck=Pin(18), mosi=Pin(19), miso=Pin(23),
  baudrate=20*1000*1000, polarity=1, phase=0)

spi2 = SPI(1, sck=Pin(21), mosi=Pin(13), miso=Pin(12),
  baudrate=20*1000*1000, polarity=0, phase=0)

display = st7789.ST7789(
    spi, 135, 240,
    reset=Pin(23, Pin.OUT),
    dc=Pin(16, Pin.OUT),
    cs = Pin(5, Pin.OUT)
)
display.start_x = 52
display.start_y = 40

def blink_leds():
    while True:
        for i, pin in enumerate(pins):
            last_pin = pins[i-1] if pin != 0 else pins[-1]
            last_pin.value(True)
            pin.value(False)
            sleep(0.3)

#import _thread
#_thread.start_new_thread(blink_leds, ())
コード例 #29
0
    return sequence[random.getrandbits(30) // div]

bl = machine.Pin(4, machine.Pin.OUT)
bl.value(1)

spi = machine.SPI(
    2,
    baudrate=30000000,
    polarity=1,
    phase=1,
    sck=machine.Pin(18),
    mosi=machine.Pin(19))

display = st7789.ST7789(
    spi, 135, 240,
    reset=machine.Pin(23, machine.Pin.OUT),
    cs=machine.Pin(5, machine.Pin.OUT),
    dc=machine.Pin(16, machine.Pin.OUT))

display.init()
display.fill(st7789.BLACK)

row = 0
again = True
while again:
    color = st7789.color565(
        random.getrandbits(8),
        random.getrandbits(8),
        random.getrandbits(8))

    row += 32