Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. from rgbmatrix import RGBMatrix, RGBMatrixOptions
  3. from PIL import Image
  4. class PiMatrix:
  5. def __init__(self):
  6. # TODO configurable
  7. self.width = 32
  8. self.height = 32
  9. options = RGBMatrixOptions()
  10. options.rows = 32
  11. options.cols = 32
  12. options.chain_length = 1
  13. options.parallel = 1
  14. options.row_address_type = 0
  15. options.multiplexing = 0
  16. options.pwm_bits = 11
  17. options.brightness = 100
  18. options.pwm_lsb_nanoseconds = 130
  19. options.led_rgb_sequence = 'RGB'
  20. #options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
  21. options.gpio_slowdown = 2
  22. options.pixel_mapper_config = "Rotate:270"
  23. self.matrix = RGBMatrix(options = options)
  24. self.loop_start() # initialize with blank image for ScrollText constructor
  25. def loop_start(self):
  26. self.image = Image.new('RGB', (self.width, self.height))
  27. return False # no input, never quit on our own
  28. def loop_end(self):
  29. self.matrix.SetImage(self.image.convert('RGB'))
  30. def debug_loop(self, func = None):
  31. while True:
  32. if self.loop_start():
  33. break
  34. if func != None:
  35. func()
  36. self.loop_end()
  37. def set_pixel(self, x, y, color):
  38. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  39. return
  40. self.image.putpixel((int(x), int(y)), color)
  41. if __name__ == "__main__":
  42. t = PiMatrix()
  43. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))