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

pi.py 2.0KB

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