12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- from rgbmatrix import RGBMatrix, RGBMatrixOptions
- from PIL import Image
-
- class PiMatrix:
- def __init__(self):
-
- self.width = 32
- self.height = 32
-
- options = RGBMatrixOptions()
- options.rows = 32
- options.cols = 32
- options.chain_length = 1
- options.parallel = 1
- options.row_address_type = 0
- options.multiplexing = 0
- options.pwm_bits = 11
- options.brightness = 100
- options.pwm_lsb_nanoseconds = 130
- options.led_rgb_sequence = 'RGB'
-
- options.gpio_slowdown = 2
- options.pixel_mapper_config = "Rotate:270"
-
- self.matrix = RGBMatrix(options = options)
-
- self.loop_start()
-
- def loop_start(self):
- self.image = Image.new('RGB', (self.width, self.height))
- return False
-
- def loop_end(self):
- self.matrix.SetImage(self.image.convert('RGB'))
-
- def debug_loop(self, func = None):
- while True:
- if self.loop_start():
- break
- if func != None:
- func()
- self.loop_end()
-
- def set_pixel(self, x, y, color):
- if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
- return
-
- self.image.putpixel((int(x), int(y)), color)
-
- if __name__ == "__main__":
- t = PiMatrix()
- t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))
|