Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

pi.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # ----------------------------------------------------------------------------
  9. # "THE BEER-WARE LICENSE" (Revision 42):
  10. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  11. # you can do whatever you want with this stuff. If we meet some day, and you
  12. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  13. # ----------------------------------------------------------------------------
  14. from rgbmatrix import RGBMatrix, RGBMatrixOptions
  15. from PIL import Image
  16. class PiMatrix:
  17. def __init__(self):
  18. # TODO configurable
  19. self.width = 32
  20. self.height = 32
  21. options = RGBMatrixOptions()
  22. options.rows = 32
  23. options.cols = 32
  24. options.chain_length = 1
  25. options.parallel = 1
  26. options.row_address_type = 0
  27. options.multiplexing = 0
  28. options.pwm_bits = 11
  29. options.brightness = 100
  30. options.pwm_lsb_nanoseconds = 130
  31. options.led_rgb_sequence = 'RGB'
  32. #options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
  33. options.gpio_slowdown = 2
  34. options.pixel_mapper_config = "Rotate:270"
  35. self.matrix = RGBMatrix(options = options)
  36. self.loop_start() # initialize with blank image for ScrollText constructor
  37. def loop_start(self):
  38. self.image = Image.new('RGB', (self.width, self.height))
  39. return False # no input, never quit on our own
  40. def loop_end(self):
  41. self.matrix.SetImage(self.image.convert('RGB'))
  42. def debug_loop(self, func = None):
  43. while True:
  44. if self.loop_start():
  45. break
  46. if func != None:
  47. func()
  48. self.loop_end()
  49. def set_pixel(self, x, y, color):
  50. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  51. return
  52. self.image.putpixel((int(x), int(y)), color)
  53. if __name__ == "__main__":
  54. t = PiMatrix()
  55. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))