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.

55 lines
1.5 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. """
  2. Writes "Hello!" in random colors at random locations.
  3. """
  4. import random
  5. from machine import Pin, SPI
  6. import st7789
  7. # Choose a font
  8. #from fonts import vga1_8x8 as font
  9. #from fonts import vga2_8x8 as font
  10. #from fonts import vga1_8x16 as font
  11. #from fonts import vga2_8x16 as font
  12. #from fonts import vga1_16x16 as font
  13. #from fonts import vga1_bold_16x16 as font
  14. #from fonts import vga2_16x16 as font
  15. from fonts import vga2_bold_16x16 as font
  16. def main():
  17. tft = st7789.ST7789(
  18. SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
  19. 135,
  20. 240,
  21. reset=Pin(23, Pin.OUT),
  22. cs=Pin(5, Pin.OUT),
  23. dc=Pin(16, Pin.OUT),
  24. backlight=Pin(4, Pin.OUT),
  25. rotation=3
  26. )
  27. tft.init()
  28. while True:
  29. for rotation in range(4):
  30. tft.rotation(rotation)
  31. tft.fill(0)
  32. col_max = tft.width() - font.WIDTH*6
  33. row_max = tft.height() - font.HEIGHT
  34. for _ in range(250):
  35. tft.text(
  36. font,
  37. "Hello!",
  38. random.randint(0, col_max),
  39. random.randint(0, row_max),
  40. st7789.color565(
  41. random.getrandbits(8),
  42. random.getrandbits(8),
  43. random.getrandbits(8)),
  44. st7789.color565(
  45. random.getrandbits(8),
  46. random.getrandbits(8),
  47. random.getrandbits(8))
  48. )
  49. main()