Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

pi.py 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 * 4, 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. import util
  72. t = PiMatrix()
  73. util.loop(t, lambda: t.set_pixel(15, 15, (255, 255, 255)))