Dépot de code divers pour mon TTGO v1.1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

8 months ago
  1. """
  2. Smoothly scrolls all font characters up the screen.
  3. Only works with fonts with heights that are even multiples of the screen height, (i.e. 8 or 16 pixels high)
  4. Non-functionnal: after some chars the screen is broken
  5. """
  6. import utime
  7. import random
  8. from machine import Pin, SPI
  9. import st7789
  10. # Choose a font
  11. #from fonts import vga1_8x8 as font
  12. #from fonts import vga2_8x8 as font
  13. #from fonts import vga1_8x16 as font
  14. from fonts import vga2_8x16 as font
  15. #from fonts import vga1_16x16 as font
  16. #from fonts import vga1_bold_16x16 as font
  17. #from fonts import vga2_16x16 as font
  18. #from fonts import vga2_bold_16x16 as font
  19. def main():
  20. tft = st7789.ST7789(
  21. SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
  22. 135,
  23. 240,
  24. reset=Pin(23, Pin.OUT),
  25. cs=Pin(5, Pin.OUT),
  26. dc=Pin(16, Pin.OUT),
  27. backlight=Pin(4, Pin.OUT),
  28. rotation=0
  29. )
  30. tft.init()
  31. last_line = tft.height() - font.HEIGHT
  32. tfa = 40
  33. tfb = 40
  34. tft.vscrdef(tfa, 240, tfb)
  35. tft.fill(st7789.BLUE)
  36. scroll = 0
  37. character = 0
  38. while True:
  39. tft.fill_rect(0,scroll, tft.width(), 1, st7789.BLUE)
  40. if scroll % font.HEIGHT == 0:
  41. tft.text(
  42. font,
  43. '\\x{:02x}= {:s} '.format(character, chr(character)),
  44. 0,
  45. (scroll + last_line) % tft.height(),
  46. st7789.WHITE,
  47. st7789.BLUE)
  48. character = character +1 if character < 256 else 0
  49. tft.vscsad(scroll+tfa)
  50. scroll +=1
  51. if scroll == tft.height:
  52. scroll = 0
  53. utime.sleep(0.01)
  54. main()