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.

70 lines
1.6 KiB

8 months ago
  1. import time
  2. from machine import Pin, SPI
  3. import st7789 as st7789
  4. from random import randrange, choice
  5. def hsv_to_rgb(h, s, v):
  6. if s == 0.0:
  7. return v, v, v
  8. i = int(h * 6.0) # XXX assume int() truncates!
  9. f = (h * 6.0) - i
  10. p = v * (1.0 - s)
  11. q = v * (1.0 - s * f)
  12. t = v * (1.0 - s * (1.0 - f))
  13. i = i % 6
  14. if i == 0:
  15. return int(v * 255), int(t * 255), int(p * 255)
  16. if i == 1:
  17. return int(q * 255), int(v * 255), int(p * 255)
  18. if i == 2:
  19. return int(p * 255), int(v * 255), int(t * 255)
  20. if i == 3:
  21. return int(p * 255), int(q * 255), int(v * 255)
  22. if i == 4:
  23. return int(t * 255), int(p * 255), int(v * 255)
  24. if i == 5:
  25. return int(v * 255), int(p * 255), int(q * 255)
  26. # Cannot get here
  27. def rainbow():
  28. print('RAINBOW')
  29. for i in range(240):
  30. color = st7789.color565(*hsv_to_rgb(i / 240, 1.0, 1.0))
  31. tft.hline(0, i, 135, color)
  32. def fill():
  33. print('FILL')
  34. tft.fill_rect(0, 0, 135, 240, st7789.color565(
  35. randrange(0, 255), randrange(0, 255), randrange(0, 255)
  36. ))
  37. def main():
  38. p1 = Pin(0, Pin.IN)
  39. p2 = Pin(35, Pin.IN)
  40. time.sleep(0.5)
  41. tft = st7789.ST7789(
  42. SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
  43. 135,
  44. 240,
  45. reset=Pin(23, Pin.OUT),
  46. cs=Pin(5, Pin.OUT),
  47. dc=Pin(16, Pin.OUT),
  48. backlight=Pin(4, Pin.OUT),
  49. rotation=0
  50. )
  51. tft.init()
  52. time.sleep(0.5)
  53. fill()
  54. while True:
  55. if not p1.value():
  56. rainbow()
  57. elif not p2.value():
  58. fill()
  59. time.sleep(0.1)
  60. main()