Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pi.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, w = 32, h = 32):
  18. self.width = w
  19. self.height = h
  20. options = RGBMatrixOptions()
  21. options.rows = w
  22. options.cols = h
  23. options.chain_length = 1
  24. options.parallel = 1
  25. options.row_address_type = 0
  26. options.multiplexing = 0
  27. options.pwm_bits = 11
  28. options.brightness = 100
  29. options.pwm_lsb_nanoseconds = 130
  30. options.led_rgb_sequence = 'RGB'
  31. #options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
  32. options.gpio_slowdown = 2
  33. options.pixel_mapper_config = "Rotate:270"
  34. self.matrix = RGBMatrix(options = options)
  35. self.loop_start() # initialize with blank image for ScrollText constructor
  36. def loop_start(self):
  37. self.image = Image.new('RGB', (self.width, self.height))
  38. return False # no input, never quit on our own
  39. def loop_end(self):
  40. self.matrix.SetImage(self.image.convert('RGB'))
  41. def debug_loop(self, func = None):
  42. while True:
  43. if self.loop_start():
  44. break
  45. if func != None:
  46. func()
  47. self.loop_end()
  48. def set_pixel(self, x, y, color):
  49. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  50. return
  51. self.image.putpixel((int(x), int(y)), color)
  52. if __name__ == "__main__":
  53. t = PiMatrix(32, 32)
  54. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))