Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

pico.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env python3
  2. # For the Pimoroni Interstate75 Raspberry Pi Pico RGB LED Matrix interface:
  3. # https://github.com/pimoroni/pimoroni-pico
  4. #
  5. # ----------------------------------------------------------------------------
  6. # "THE BEER-WARE LICENSE" (Revision 42):
  7. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  8. # you can do whatever you want with this stuff. If we meet some day, and you
  9. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  10. # ----------------------------------------------------------------------------
  11. import interstate75
  12. import hub75
  13. from mapper import MapperReduceBrightness
  14. import time
  15. from machine import Pin
  16. class PicoMatrix:
  17. def __init__(self, w = 32, h = 32):
  18. self.width = w # x-axis
  19. self.height = h # y-axis
  20. self.panelW = w # x-axis
  21. self.panelH = h # y-axis
  22. # compatibility to TestGUI
  23. self.multiplier = 1.0
  24. if (w != 32) or (h != 32):
  25. raise RuntimeError("TODO not yet supported")
  26. mode = interstate75.DISPLAY_INTERSTATE75_32X32
  27. self.matrix = interstate75.Interstate75(display = mode, panel_type = hub75.PANEL_FM6126A)
  28. self.black = self.matrix.display.create_pen(0, 0, 0)
  29. self.white = self.matrix.display.create_pen(255, 255, 255)
  30. self.ledTime = time.time()
  31. self.led = Pin("LED", Pin.OUT)
  32. self.loop_start() # initialize with blank image for ScrollText constructor
  33. def loop_start(self):
  34. self.matrix.display.set_pen(self.black)
  35. self.matrix.display.clear()
  36. self.matrix.display.set_pen(self.white)
  37. return False # no input, never quit on our own
  38. def loop_end(self):
  39. self.matrix.update()
  40. def loop(self, func = None):
  41. while True:
  42. if self.loop_start():
  43. break
  44. if func != None:
  45. func()
  46. self.loop_end()
  47. now = time.time()
  48. if ((now - self.ledTime) >= 0.5) or (now < self.ledTime):
  49. self.ledTime = now
  50. self.led.toggle()
  51. self.matrix.stop()
  52. def set_pixel(self, x, y, color):
  53. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  54. return
  55. pen = self.matrix.display.create_pen(color[0], color[1], color[2])
  56. self.matrix.display.set_pen(pen)
  57. self.matrix.display.pixel(int(x), int(y))
  58. class PicoText:
  59. def __init__(self, g, fg = (255, 255, 255), bg = (0, 0, 0), c = (0, 255, 0)):
  60. self.gui = g
  61. self.fg = fg
  62. self.bg = bg
  63. self.color = c
  64. def text(self, s, f, offset = 0, earlyAbort = True, yOff = 0, compat = True):
  65. if not earlyAbort:
  66. return self.gui.matrix.display.measure_text(s, scale=1)
  67. color = self.fg
  68. if isinstance(self.gui, MapperReduceBrightness):
  69. color = self.gui.adjust(color)
  70. pen = self.gui.matrix.display.create_pen(color[0], color[1], color[2])
  71. self.gui.matrix.display.set_pen(pen)
  72. self.gui.matrix.display.set_font(f)
  73. if not compat:
  74. # absolute positioning
  75. x = offset
  76. y = yOff
  77. else:
  78. # centered, like BDF DrawText implementation
  79. fontOff = 0
  80. if f == "bitmap6":
  81. fontOff = 3
  82. elif f == "bitmap8":
  83. fontOff = 4
  84. elif f == "bitmap14_outline":
  85. fontOff = 7
  86. x = -offset
  87. y = int(self.gui.height / 2 - fontOff + yOff)
  88. self.gui.matrix.display.text(s, x, y, scale=1)
  89. if __name__ == "__main__":
  90. import time
  91. t = PicoMatrix(32, 32)
  92. s = PicoText(t)
  93. start = time.time()
  94. i = 0
  95. def helper():
  96. global s, start, i
  97. now = time.time()
  98. if ((now - start) > 2.0) or (now < start):
  99. start = now
  100. i = (i + 1) % 2
  101. if i == 0:
  102. s.text("Abgj6", "bitmap6", 0, True, 0, False)
  103. s.text("Abdgj8", "bitmap8", 0, True, 6 + 2, False)
  104. s.text("Ag14", "bitmap14_outline", 0, True, 6 + 2 + 8 + 1, False)
  105. else:
  106. s.text("Drinks:", "bitmap8", 0)
  107. t.loop(helper)