box_demo.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2017-18 Richard Hull and contributors
  4. # See LICENSE.rst for details.
  5. import time
  6. import argparse
  7. from luma.led_matrix.device import max7219
  8. from luma.core.interface.serial import spi, noop
  9. from luma.core.render import canvas
  10. from luma.core.legacy import text
  11. from luma.core.legacy.font import proportional, LCD_FONT
  12. def demo(w, h, block_orientation, rotate):
  13. # create matrix device
  14. serial = spi(port=0, device=0, gpio=noop())
  15. device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation)
  16. print("Created device")
  17. with canvas(device) as draw:
  18. draw.rectangle(device.bounding_box, outline="white")
  19. text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT))
  20. text(draw, (2, 10), "World", fill="white", font=proportional(LCD_FONT))
  21. time.sleep(300)
  22. if __name__ == "__main__":
  23. parser = argparse.ArgumentParser(description='matrix_demo arguments',
  24. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  25. parser.add_argument('--width', type=int, default=8, help='Width')
  26. parser.add_argument('--height', type=int, default=8, help='height')
  27. parser.add_argument('--block-orientation', type=int, default=-90, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
  28. parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotation factor')
  29. args = parser.parse_args()
  30. try:
  31. demo(args.width, args.height, args.block_orientation, args.rotate)
  32. except KeyboardInterrupt:
  33. pass