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)
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)))
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)))
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)
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)
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)) )
def tile(x, y, l, r, g, b, ancho=3): fhello.display.fill_rect(x, y, l, l, st7789.color565(r, g, b)) for i in range(1, ancho): fhello.display.hline(x + i, y + i, l - 2 * i, st7789.color565(r + 50, g + 50, b + 50)) fhello.display.vline(x + i, y + i, l - 2 * i, st7789.color565(r + 100, g + 100, b + 100)) fhello.display.vline(x + l - i, y + i, l - 2 * i, st7789.color565(r // 3, g // 3, b // 3)) fhello.display.hline(x + i, y + l - i, l - 2 * i, st7789.color565(r // 2, g // 2, b // 2))
def color_wheel(position): """returns a 565 color from the given position of the color wheel""" position = (255 - position) % 255 if position < 85: return st7789.color565(255 - position * 3, 0, position * 3) if position < 170: position -= 85 return st7789.color565(0, position * 3, 255 - position * 3) position -= 170 return st7789.color565(position * 3, 255 - position * 3, 0)
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)
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))
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) ) )
def test(): row = 32 while True: color = st7789.color565(random.getrandbits(8), random.getrandbits(8), random.getrandbits(8)) font_file = "/fonts/" + pick_item(fonts) ftext.text(display, font_file, "Hello!", row, 0, color, 2.0, True) row += 32 if row > 192: display.fill(st7789.BLACK) row = 0
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)))
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), ), )
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)
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)
def line(self, a): self.display.line(a[0], a[1], a[2], a[3], st7789.color565(a[4], a[5], a[6]))
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)) row += 32 #Displays random color words display.text(pick_item(fonts), "Makepython!!!", row, 0, color) if row > 192: display.fill(st7789.BLACK) row = 0 except KeyboardInterrupt: pass
# ejemplo de tetris https://gist.github.com/silvasur/565419/d9de6a84e7da000797ac681976442073045c74a4 # video tutorial https://www.youtube.com/watch?v=zfvxp7PgQ6c # tetris con pygame https://recursospython.com/codigos-de-fuente/tetris-pygame/ # ![graficos](https://e3ab9255-a-62cb3a1a-s-sites.googlegroups.com/site/ddrkirby/coding-projects/keyblox/keyblox_screen_2.png?attachauth=ANoY7cqnEjNk2seGFyLINcmmdsHvspmcinJfiUlUGY9-xbn1yczq4LYae21z7EvQv7GiTO1yEtikxPcyWBL0j9__ZZXBVbOLXJvr38BfzaecvLiAEB2PPi2wPnlTF9oLFZDLVArK-1a8XczoxbN7LVVcIKXqh6pduTLULduvMLmNyfKG1MnHAevC-zeEiA48aE1_B1VeW0a_e_vjCg4zLtehc54iWqKvmXPxrLbCK21UH_kIr8NgLfgjh3PgKQwOOwDrZA3kYJPA&attredirects=0) v = '0.6' import time import machine import st7789py as st7789 import fhello fhello.init() back_color = st7789.color565(10, 10, 10) def tile(x, y, l, r, g, b, ancho=3): fhello.display.fill_rect(x, y, l, l, st7789.color565(r, g, b)) for i in range(1, ancho): fhello.display.hline(x + i, y + i, l - 2 * i, st7789.color565(r + 50, g + 50, b + 50)) fhello.display.vline(x + i, y + i, l - 2 * i, st7789.color565(r + 100, g + 100, b + 100)) fhello.display.vline(x + l - i, y + i, l - 2 * i, st7789.color565(r // 3, g // 3, b // 3)) fhello.display.hline(x + i, y + l - i, l - 2 * i, st7789.color565(r // 2, g // 2, b // 2))