Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python3
  2. # Uses the Python bindings for the Raspberry Pi RGB LED Matrix library:
  3. # https://github.com/hzeller/rpi-rgb-led-matrix
  4. #
  5. # And the pillow Python Imaging Library:
  6. # https://github.com/python-pillow/Pillow
  7. #
  8. # For the wiring of multiple panels, check out:
  9. # https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/wiring.md#chains
  10. #
  11. # Basically each chain only stretches in the X-direction.
  12. # For the Y-direction, multiple parallel chains are used.
  13. # Up to 3 are theoretically possible with the Pi, but my hardware only supports
  14. # one.
  15. #
  16. # The physical layout of the chained panels can be different of course.
  17. # For four panels, you could do 64x64 or 32x128.
  18. # But this PiMatrix object will always present it as 128x32,
  19. # chained in the X-direction.
  20. #
  21. # Use the objects from mapper.py to adjust this.
  22. #
  23. # ----------------------------------------------------------------------------
  24. # "THE BEER-WARE LICENSE" (Revision 42):
  25. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  26. # you can do whatever you want with this stuff. If we meet some day, and you
  27. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  28. # ----------------------------------------------------------------------------
  29. from rgbmatrix import RGBMatrix, RGBMatrixOptions
  30. from PIL import Image
  31. class PiMatrix:
  32. def __init__(self, w = 32 * 2, h = 32, panelW = 32, panelH = 32):
  33. self.width = w # x-axis
  34. self.height = h # y-axis
  35. self.panelW = panelW # x-axis
  36. self.panelH = panelH # y-axis
  37. # compatibility to TestGUI
  38. self.multiplier = 1.0
  39. options = RGBMatrixOptions()
  40. options.cols = self.panelW # x-axis
  41. options.rows = self.panelH # y-axis
  42. options.chain_length = int(self.width / options.cols) # x-axis
  43. options.parallel = int(self.height / options.rows) # y-axis
  44. options.row_address_type = 0
  45. options.multiplexing = 0
  46. options.pwm_bits = 11
  47. options.brightness = 100
  48. options.pwm_lsb_nanoseconds = 130
  49. options.led_rgb_sequence = 'RGB'
  50. #options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
  51. #options.gpio_slowdown = 2
  52. #options.pixel_mapper_config = "Rotate:270"
  53. # newer Pimoroni 32x32 panels require this setting for additional
  54. # initialization of the shift-registers on there.
  55. # fortunately this also works for the older type of panels.
  56. options.panel_type = "FM6126A"
  57. self.matrix = RGBMatrix(options = options)
  58. self.loop_start() # initialize with blank image for ScrollText constructor
  59. def exit(self):
  60. pass
  61. def loop_start(self):
  62. self.image = Image.new('RGB', (self.width, self.height))
  63. return False # no input, never quit on our own
  64. def loop_end(self):
  65. self.matrix.SetImage(self.image.convert('RGB'))
  66. def set_pixel(self, x, y, color):
  67. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  68. return
  69. self.image.putpixel((int(x), int(y)), color)
  70. if __name__ == "__main__":
  71. t = PiMatrix(32, 32)
  72. util.loop(t, lambda: t.set_pixel(15, 15, (255, 255, 255)))